prince1604 commited on
Commit ·
53a61cf
1
Parent(s): 8853d7b
Fix crawling for eminentcoders.com
Browse files- src/crawler.py +17 -1
src/crawler.py
CHANGED
|
@@ -102,7 +102,23 @@ class Crawler:
|
|
| 102 |
return None
|
| 103 |
|
| 104 |
except Exception as e:
|
| 105 |
-
logger.error(f"Exception fetching {url}: {e}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
time.sleep(2 * (attempt + 1))
|
| 107 |
|
| 108 |
return None
|
|
|
|
| 102 |
return None
|
| 103 |
|
| 104 |
except Exception as e:
|
| 105 |
+
logger.error(f"Exception fetching {url} with curl_cffi: {e}. Attempting standard requests fallback...")
|
| 106 |
+
try:
|
| 107 |
+
# Fallback to standard requests (sometimes works better for simpler/older server configs)
|
| 108 |
+
import requests as standard_requests
|
| 109 |
+
# random user agent
|
| 110 |
+
headers = {
|
| 111 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 112 |
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
|
| 113 |
+
}
|
| 114 |
+
resp = standard_requests.get(url, headers=headers, timeout=30, verify=False)
|
| 115 |
+
if 200 <= resp.status_code < 300:
|
| 116 |
+
return resp.text
|
| 117 |
+
else:
|
| 118 |
+
logger.error(f"Standard requests failed with status {resp.status_code}")
|
| 119 |
+
except Exception as std_e:
|
| 120 |
+
logger.error(f"Standard requests fallback failed: {std_e}")
|
| 121 |
+
|
| 122 |
time.sleep(2 * (attempt + 1))
|
| 123 |
|
| 124 |
return None
|