prince1604 commited on
Commit ·
1f8e73e
1
Parent(s): 357e12c
Make playwright-stealth optional and fix import errors
Browse files- src/crawler.py +13 -3
src/crawler.py
CHANGED
|
@@ -155,7 +155,14 @@ class Crawler:
|
|
| 155 |
|
| 156 |
try:
|
| 157 |
from playwright.sync_api import sync_playwright
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
logger.info("[-] playwright_libraries_imported_successfully")
|
| 160 |
except ImportError as e:
|
| 161 |
logger.error(f"[!] playwright_import_failed: {e}")
|
|
@@ -194,8 +201,11 @@ class Crawler:
|
|
| 194 |
logger.info("[-] page_created")
|
| 195 |
|
| 196 |
# Apply Stealth
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Block resources
|
| 201 |
page.route("**/*.{png,jpg,jpeg,gif,svg,woff,woff2,ttf,otf}", lambda route: route.abort())
|
|
|
|
| 155 |
|
| 156 |
try:
|
| 157 |
from playwright.sync_api import sync_playwright
|
| 158 |
+
# Try importing stealth, if fails, continue without it but warn
|
| 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
|
| 165 |
+
|
| 166 |
logger.info("[-] playwright_libraries_imported_successfully")
|
| 167 |
except ImportError as e:
|
| 168 |
logger.error(f"[!] playwright_import_failed: {e}")
|
|
|
|
| 201 |
logger.info("[-] page_created")
|
| 202 |
|
| 203 |
# Apply Stealth
|
| 204 |
+
if has_stealth:
|
| 205 |
+
stealth_sync(page)
|
| 206 |
+
logger.info("[-] stealth_sync_applied: 'navigator.webdriver' masked")
|
| 207 |
+
else:
|
| 208 |
+
logger.info("[-] stealth_disabled: library not found")
|
| 209 |
|
| 210 |
# Block resources
|
| 211 |
page.route("**/*.{png,jpg,jpeg,gif,svg,woff,woff2,ttf,otf}", lambda route: route.abort())
|