prince1604 commited on
Commit ·
94af2f2
1
Parent(s): d92f150
Fix Amazon crawling: Add Start URL Retry logic and more block keywords
Browse files- src/__pycache__/crawler.cpython-314.pyc +0 -0
- src/crawler.py +16 -1
src/__pycache__/crawler.cpython-314.pyc
CHANGED
|
Binary files a/src/__pycache__/crawler.cpython-314.pyc and b/src/__pycache__/crawler.cpython-314.pyc differ
|
|
|
src/crawler.py
CHANGED
|
@@ -95,7 +95,10 @@ class Crawler:
|
|
| 95 |
"captcha",
|
| 96 |
"security check",
|
| 97 |
"turn on javascript",
|
| 98 |
-
"challenge.js"
|
|
|
|
|
|
|
|
|
|
| 99 |
]
|
| 100 |
|
| 101 |
if any(k in lower_content for k in block_keywords):
|
|
@@ -268,6 +271,18 @@ class Crawler:
|
|
| 268 |
# Unpack result
|
| 269 |
_, images, raw_links = result
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
logger.info(f"Crawled [{pages_crawled + 1}]: {url}")
|
| 272 |
site_data[url] = images
|
| 273 |
pages_crawled += 1
|
|
|
|
| 95 |
"captcha",
|
| 96 |
"security check",
|
| 97 |
"turn on javascript",
|
| 98 |
+
"challenge.js",
|
| 99 |
+
"api-services-support@amazon.com",
|
| 100 |
+
"we just need to make sure you're not a robot",
|
| 101 |
+
"type the characters you see in this image"
|
| 102 |
]
|
| 103 |
|
| 104 |
if any(k in lower_content for k in block_keywords):
|
|
|
|
| 271 |
# Unpack result
|
| 272 |
_, images, raw_links = result
|
| 273 |
|
| 274 |
+
# --- CRITICAL FIX: Start URL Retry for Dynamic/Blocked Pages ---
|
| 275 |
+
if url == start_url and len(raw_links) < 5:
|
| 276 |
+
logger.warning(f"Start URL {url} returned only {len(raw_links)} links. Likely JS-heavy or blocked. Forcing Playwright retry...")
|
| 277 |
+
# Run Playwright directly in main thread for the seed
|
| 278 |
+
pw_content = self._fetch_playwright(url)
|
| 279 |
+
if pw_content:
|
| 280 |
+
images = self.extract_images(pw_content, url)
|
| 281 |
+
soup = BeautifulSoup(pw_content, 'html.parser')
|
| 282 |
+
raw_links = [link.get('href') for link in soup.find_all('a', href=True)]
|
| 283 |
+
logger.info(f"Playwright retry found {len(raw_links)} links.")
|
| 284 |
+
# ---------------------------------------------------------------
|
| 285 |
+
|
| 286 |
logger.info(f"Crawled [{pages_crawled + 1}]: {url}")
|
| 287 |
site_data[url] = images
|
| 288 |
pages_crawled += 1
|