Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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 |
-
#
|
| 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 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
else:
|
| 323 |
-
#
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
if
|
| 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.", "")
|