prince1604 commited on
Commit
3c07190
·
1 Parent(s): 1f8e73e

Fix silent failure on blocked crawls

Browse files
Files changed (2) hide show
  1. api.py +2 -2
  2. src/crawler.py +7 -5
api.py CHANGED
@@ -142,9 +142,9 @@ def run_scan_job(job_id: str, domain: str, limit: int, is_auto: bool = False):
142
  progress_callback=progress_callback
143
  )
144
 
145
- if not site_data and blocked_reason:
146
  JOBS[job_id]["status"] = "error"
147
- JOBS[job_id]["error"] = f"Blocked: {blocked_reason}"
148
  return
149
 
150
  JOBS[job_id]["message"] = "Analyzing Images..."
 
142
  progress_callback=progress_callback
143
  )
144
 
145
+ if not site_data:
146
  JOBS[job_id]["status"] = "error"
147
+ JOBS[job_id]["error"] = f"Scan failed: {blocked_reason or 'No pages found (Access Denied or JS Blocked)'}"
148
  return
149
 
150
  JOBS[job_id]["message"] = "Analyzing Images..."
src/crawler.py CHANGED
@@ -159,6 +159,7 @@ class Crawler:
159
  try:
160
  from playwright_stealth import stealth_sync
161
  has_stealth = True
 
162
  except ImportError:
163
  logger.warning("playwright-stealth not found. Running without stealth mode.")
164
  has_stealth = False
@@ -243,6 +244,7 @@ class Crawler:
243
  block_reason = "Content: Verify Human"
244
 
245
  if is_blocked:
 
246
  logger.warning(f"[!] WAF_DETECTED: {block_reason}. Initiating countermeasures...")
247
 
248
  # 1. Mouse Action
@@ -443,11 +445,11 @@ class Crawler:
443
  f.cancel()
444
 
445
  # Final block check: if we scraped 0 pages or only 1 page with 0 images and blocked_reason is set
446
- if pages_crawled == 0 and self.blocked_reason:
447
- pass # blocked_reason is already set
448
- elif pages_crawled > 0 and not self.blocked_reason:
449
- # Check if we successfully scanned but found suspiciously nothing?
450
- pass
451
 
452
  return site_data, len(self.visited_urls), self.blocked_reason
453
 
 
159
  try:
160
  from playwright_stealth import stealth_sync
161
  has_stealth = True
162
+ logger.info("[-] playwright-stealth imported successfully")
163
  except ImportError:
164
  logger.warning("playwright-stealth not found. Running without stealth mode.")
165
  has_stealth = False
 
244
  block_reason = "Content: Verify Human"
245
 
246
  if is_blocked:
247
+ self.blocked_reason = block_reason
248
  logger.warning(f"[!] WAF_DETECTED: {block_reason}. Initiating countermeasures...")
249
 
250
  # 1. Mouse Action
 
445
  f.cancel()
446
 
447
  # Final block check: if we scraped 0 pages or only 1 page with 0 images and blocked_reason is set
448
+ # Final block check: if we scraped 0 pages or only 1 page with 0 images and blocked_reason is set
449
+ if pages_crawled == 0 and not self.blocked_reason:
450
+ # If we have 0 pages, it means the start_url failed to fetch completely.
451
+ self.blocked_reason = "Failed to access domain (All tiers failed)"
452
+ site_data = None # Ensure it's treated as failure
453
 
454
  return site_data, len(self.visited_urls), self.blocked_reason
455