Commit
·
c2f18d6
1
Parent(s):
f6faea4
Changed timeouts
Browse files
scrape.py
CHANGED
|
@@ -286,71 +286,71 @@ async def scrape_page(
|
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
-
@app.get("/search_leads")
|
| 290 |
-
async def search_leads(
|
| 291 |
-
|
| 292 |
-
):
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
|
| 355 |
|
| 356 |
|
|
|
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
+
# @app.get("/search_leads")
|
| 290 |
+
# async def search_leads(
|
| 291 |
+
# query: str = Query(..., description="Search term for business leads")
|
| 292 |
+
# ):
|
| 293 |
+
# logger.info(f"Searching Google Maps for: {query}")
|
| 294 |
+
|
| 295 |
+
# async with async_playwright() as p:
|
| 296 |
+
# browser = await p.chromium.launch(headless=True)
|
| 297 |
+
# page = await browser.new_page()
|
| 298 |
+
|
| 299 |
+
# try:
|
| 300 |
+
# # Go to Google Maps
|
| 301 |
+
# await page.goto("https://www.google.com/maps", wait_until="networkidle")
|
| 302 |
+
|
| 303 |
+
# # Accept cookies if present (optional, depends on region)
|
| 304 |
+
# try:
|
| 305 |
+
# await page.click('button[aria-label="Accept all"]', timeout=180000)
|
| 306 |
+
# except:
|
| 307 |
+
# pass
|
| 308 |
+
|
| 309 |
+
# # Type the query in the search box and press Enter
|
| 310 |
+
# await page.fill('input#searchboxinput', query)
|
| 311 |
+
# await page.click('button#searchbox-searchbutton')
|
| 312 |
+
|
| 313 |
+
# # Wait for search results to load - selector for listings container
|
| 314 |
+
# await page.wait_for_selector('div[role="article"]', timeout=180000)
|
| 315 |
+
|
| 316 |
+
# # Scroll results container to load more items (optional)
|
| 317 |
+
# # For now, scrape the visible ones
|
| 318 |
+
|
| 319 |
+
# # Extract data from listings
|
| 320 |
+
# results = await page.evaluate("""
|
| 321 |
+
# () => {
|
| 322 |
+
# const listings = [];
|
| 323 |
+
# const elements = document.querySelectorAll('div[role="article"]');
|
| 324 |
+
# elements.forEach(el => {
|
| 325 |
+
# const nameEl = el.querySelector('h3 span');
|
| 326 |
+
# const name = nameEl ? nameEl.innerText : null;
|
| 327 |
+
|
| 328 |
+
# const addressEl = el.querySelector('[data-tooltip="Address"]');
|
| 329 |
+
# const address = addressEl ? addressEl.innerText : null;
|
| 330 |
+
|
| 331 |
+
# const phoneEl = el.querySelector('button[data-tooltip="Copy phone number"]');
|
| 332 |
+
# const phone = phoneEl ? phoneEl.getAttribute('aria-label')?.replace('Copy phone number ', '') : null;
|
| 333 |
+
|
| 334 |
+
# const websiteEl = el.querySelector('a[aria-label*="Website"]');
|
| 335 |
+
# const website = websiteEl ? websiteEl.href : null;
|
| 336 |
+
|
| 337 |
+
# listings.push({name, address, phone, website});
|
| 338 |
+
# });
|
| 339 |
+
# return listings;
|
| 340 |
+
# }
|
| 341 |
+
# """)
|
| 342 |
+
|
| 343 |
+
# await browser.close()
|
| 344 |
+
|
| 345 |
+
# # Filter out empty entries
|
| 346 |
+
# filtered = [r for r in results if r['name']]
|
| 347 |
+
|
| 348 |
+
# return {"query": query, "results_count": len(filtered), "results": filtered}
|
| 349 |
+
|
| 350 |
+
# except Exception as e:
|
| 351 |
+
# await browser.close()
|
| 352 |
+
# logger.error(f"Error during Google Maps search scraping: {str(e)}")
|
| 353 |
+
# raise HTTPException(status_code=500, detail=f"Search scraping error: {str(e)}")
|
| 354 |
|
| 355 |
|
| 356 |
|