mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-20 13:48:16 +02:00
feat: add web scraping and search services using Playwright with anti-detection mechanisms.
This commit is contained in:
1 parent
7a73650264
commit
091caad347
3 files changed
+98
-27
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from playwright.async_api import async_playwright
|
||||
from app.services.scraper_service import ScraperService
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def verify_fix():
|
||||
logger.info("Starting verification...")
|
||||
|
||||
# Mock browserless URL if not set
|
||||
if not os.getenv("BROWSERLESS_URL"):
|
||||
os.environ["BROWSERLESS_URL"] = "ws://browserless:3000"
|
||||
|
||||
playwright = await async_playwright().start()
|
||||
try:
|
||||
# Connect to browserless (or launch local if not available, but code expects connect)
|
||||
# For this test, we might need to mock the browser object if we can't actually connect
|
||||
# But let's try to just create a local browser for testing purposes if connect fails
|
||||
# Actually, the code expects a browser object.
|
||||
|
||||
logger.info("Launching local browser for test...")
|
||||
browser = await playwright.chromium.launch()
|
||||
|
||||
logger.info("Calling scrape_item with browser argument...")
|
||||
try:
|
||||
# We pass a dummy URL, we expect it might fail scraping but NOT raise TypeError
|
||||
await ScraperService.scrape_item(
|
||||
url="https://example.com",
|
||||
browser=browser,
|
||||
timeout=5000 # Short timeout
|
||||
)
|
||||
logger.info("SUCCESS: scrape_item accepted the browser argument!")
|
||||
except TypeError as e:
|
||||
logger.error(f"FAILURE: TypeError raised: {e}")
|
||||
except Exception as e:
|
||||
logger.info(f"Scraping failed as expected (network/etc), but argument was accepted: {e}")
|
||||
|
||||
await browser.close()
|
||||
|
||||
finally:
|
||||
await playwright.stop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(verify_fix())
|
||||
Reference in new issue
Block a user