Skip to content

Fix 403 errors on CDN-protected sites and auto-recover broken cache states - #67

Open
fakhavan wants to merge 1 commit into
obeone:mainfrom
fakhavan:main
Open

Fix 403 errors on CDN-protected sites and auto-recover broken cache states #67
fakhavan wants to merge 1 commit into
obeone:mainfrom
fakhavan:main

Conversation

@fakhavan

Copy link
Copy Markdown

Problem 1: 403 Forbidden on child pages

Some sites (particularly those behind CDN/WAF providers like WPX Cloud, LiteSpeed, Cloudflare) block requests that lack standard browser headers. The scraper was sending requests with no User-Agent and no Referer, causing the homepage to return 200 while all child pages returned 403 — resulting in a crawl of only 1 page.

Fix: Set a realistic User-Agent and Referer (base URL) on the session at initialization.

Problem 2: Broken cache state causes silent re-run failures

If a scraping run was interrupted or failed after a URL was marked visited but before its page content was stored, re-running the scraper would silently exit with no output. The progress bar would show 1/1 complete, but the exported files would be empty. There was no way to detect or recover from this without manually deleting the .sqlite cache file.

Fix: Added reset_if_no_content(url) to DatabaseManager, called on the starting URL before the crawl loop. It resets visited = FALSE for any URL that has no corresponding page content, allowing the scraper to automatically recover on the next run without user intervention and without affecting successfully scraped pages.

Files changed:

  • crawler_to_md/scraper.py — browser headers on session init; call reset_if_no_content on start
  • crawler_to_md/database_manager.py — new reset_if_no_content(url) method

… cache states

Implement a method in DatabaseManager to reset a link's visited status if it has no corresponding page content. Update Scraper to utilize this method when a URL is processed without valid content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant