Spaces:
Sleeping
Sleeping
Update schema.py
Browse files
schema.py
CHANGED
|
@@ -110,19 +110,43 @@ def extract_universal_sizing(text: str) -> str:
|
|
| 110 |
return ""
|
| 111 |
|
| 112 |
def clean_google_link(url: str) -> str:
|
| 113 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
try:
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
return url
|
| 127 |
|
| 128 |
def parse_price_locally(dense_text, product_name):
|
|
|
|
| 110 |
return ""
|
| 111 |
|
| 112 |
def clean_google_link(url: str) -> str:
|
| 113 |
+
"""
|
| 114 |
+
Strips Google Shopping tracking wrappers and redirects,
|
| 115 |
+
returning the direct outbound merchant website URL instantly.
|
| 116 |
+
"""
|
| 117 |
+
if not url:
|
| 118 |
+
return ""
|
| 119 |
+
|
| 120 |
+
if "google.com" not in url:
|
| 121 |
+
return url
|
| 122 |
+
|
| 123 |
try:
|
| 124 |
+
# Step 1: Extract parameters from query string configurations
|
| 125 |
+
decoded_link = unquote(url)
|
| 126 |
+
parsed_url = urlparse(decoded_link)
|
| 127 |
+
qs = parse_qs(parsed_url.query)
|
| 128 |
+
|
| 129 |
+
# Intercept standard routing redirects directly
|
| 130 |
+
for redirect_param in ['adurl', 'url', 'q', 'link', 'shopping_redirect']:
|
| 131 |
+
if redirect_param in qs:
|
| 132 |
+
target_url = qs[redirect_param][0]
|
| 133 |
+
if target_url.startswith(("http://", "https://")):
|
| 134 |
+
return target_url
|
| 135 |
+
|
| 136 |
+
# Step 2: Heuristic text fallback layer
|
| 137 |
+
found_urls = re.findall(r'(https?://[^\s&]+)', decoded_link)
|
| 138 |
+
for sub_url in found_urls:
|
| 139 |
+
if "google.com" not in sub_url and "googleadservices.com" not in sub_url:
|
| 140 |
+
if "?" in sub_url:
|
| 141 |
+
base_part, query_part = sub_url.split("?", 1)
|
| 142 |
+
# Exclude typical tracking tokens
|
| 143 |
+
query_part = re.sub(re.compile(r'&?(gclid|gclsrc|utm_)[^&]*'), '', query_part)
|
| 144 |
+
sub_url = f"{base_part}?{query_part}".rstrip('?')
|
| 145 |
+
return sub_url
|
| 146 |
+
|
| 147 |
+
except Exception as e:
|
| 148 |
+
print(f"⚠️ [Link Extractor Error] Could not unwrap target metadata: {e}")
|
| 149 |
+
|
| 150 |
return url
|
| 151 |
|
| 152 |
def parse_price_locally(dense_text, product_name):
|