ghstedpixel commited on
Commit
36d797c
·
verified ·
1 Parent(s): 955b2d0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -16
main.py CHANGED
@@ -202,7 +202,7 @@ async def handle_search(
202
  # Parallel Engine Lookups
203
  markdown_deals, product_offers = await asyncio.gather(
204
  fetch_deals_standalone(target_item),
205
- scan_prices(target_item)
206
  )
207
 
208
  if original_site_deal:
@@ -312,23 +312,29 @@ async def handle_search(
312
  elif "link" not in d and "url" in d:
313
  d["link"] = d["url"]
314
 
315
- # Intercept and break out of SerpApi Google tracking loops/fallback links
316
  current_url = d.get("url", "")
317
- if current_url and ("google.com/search" in current_url or "google.com/shopping" in current_url):
318
- # Check if there's an explicit third-party merchant domain assigned to fall back to
319
- src_domain = d.get("source", "").strip().lower()
320
- if src_domain and "." in src_domain and "google" not in src_domain:
321
- d["url"] = f"https://www.{src_domain}" if not src_domain.startswith("http") else src_domain
 
 
 
 
 
 
 
 
 
 
 
322
  else:
323
- # Try to extract tracking variables from embedded params inside the SerpApi link wrapper
324
- try:
325
- parsed_params = parse_qs(urlparse(current_url).query)
326
- if parsed_params.get("url"):
327
- d["url"] = parsed_params["url"][0]
328
- elif parsed_params.get("adurl"):
329
- d["url"] = parsed_params["adurl"][0]
330
- except:
331
- pass
332
 
333
  try:
334
  d["source_domain"] = d.get("source") or urlparse(d["url"]).netloc.replace("www.", "")
 
202
  # Parallel Engine Lookups
203
  markdown_deals, product_offers = await asyncio.gather(
204
  fetch_deals_standalone(target_item),
205
+ scan_prices(target_item, requested_size, search_mode)
206
  )
207
 
208
  if original_site_deal:
 
312
  elif "link" not in d and "url" in d:
313
  d["link"] = d["url"]
314
 
315
+ # Deep-Unwrap tracking strings first to secure the absolute specific product page slug path
316
  current_url = d.get("url", "")
317
+ if current_url and ("google.com/search" in current_url or "google.com/shopping" in current_url or "google.com/url" in current_url):
318
+ extracted_target_url = None
319
+ try:
320
+ parsed_params = parse_qs(urlparse(current_url).query)
321
+ for param_key in ["q", "url", "adurl"]:
322
+ if parsed_params.get(param_key):
323
+ candidate_link = parsed_params[param_key][0]
324
+ if candidate_link.startswith("http") and "google.com" not in candidate_link:
325
+ extracted_target_url = candidate_link
326
+ break
327
+ except:
328
+ pass
329
+
330
+ if extracted_target_url:
331
+ d["url"] = extracted_target_url
332
+ d["link"] = extracted_target_url
333
  else:
334
+ # Fallback to home domain only if parameters do not contain any clean path strings
335
+ src_domain = d.get("source", "").strip().lower()
336
+ if src_domain and "." in src_domain and "google" not in src_domain:
337
+ d["url"] = f"https://www.{src_domain}" if not src_domain.startswith("http") else src_domain
 
 
 
 
 
338
 
339
  try:
340
  d["source_domain"] = d.get("source") or urlparse(d["url"]).netloc.replace("www.", "")