feat(py-monitor): add normalize_product_url()
This commit is contained in:
1 parent
91593210e8
commit
3fb52f40d2
1 file changed
+10
@@ -17,3 +17,13 @@ def strip_thumbnail_suffix(url):
|
||||
return url.replace("_progressive_thumbnail", "")
|
||||
|
||||
|
||||
def normalize_product_url(url):
|
||||
"""剥掉 query/fragment:同一个商品被两个 watch 抓到、或带追踪后缀时仍算同一条。"""
|
||||
if not url:
|
||||
return ""
|
||||
try:
|
||||
p = urllib.parse.urlsplit(str(url).strip())
|
||||
path = (p.path or "").rstrip("/")
|
||||
return urllib.parse.urlunsplit((p.scheme.lower(), p.netloc.lower(), path, "", ""))
|
||||
except Exception:
|
||||
return str(url).strip()
|
||||
Reference in new issue
Block a user