Skip to content

Commit c5a554c

Browse files
authored
Update E-commerce-Price-Tracker-Ebay.py
1 parent 2b4172c commit c5a554c

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

104-E-commerce-price-tracker/E-commerce-Price-Tracker-Ebay.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
from tkinterdnd2 import TkinterDnD, DND_FILES
1111
from urllib.parse import urlparse
1212

13+
from urllib.parse import urlparse
14+
15+
ALLOWED_HOSTS = {"www.ebay.com", "ebay.com"}
16+
17+
def is_allowed_ebay_url(url):
18+
try:
19+
parsed = urlparse(url)
20+
hostname = parsed.hostname.lower() if parsed.hostname else ""
21+
return hostname in ALLOWED_HOSTS
22+
except Exception:
23+
return False
24+
1325
# =================== Utility Functions ===================
1426
def resource_path(file_name):
1527
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
@@ -31,15 +43,17 @@ def fetch_price(url):
3143
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
3244

3345
# Clean eBay URLs
34-
if "ebay.com" in url:
46+
if is_allowed_ebay_url(url):
3547
url = clean_ebay_url(url)
48+
else:
49+
return "Error: URL not allowed"
3650

3751
resp = requests.get(url, headers=headers, timeout=10)
3852
resp.raise_for_status()
3953
soup = BeautifulSoup(resp.text, "html.parser")
4054

4155
# ---------------- eBay ----------------
42-
if "ebay.com" in url:
56+
if is_allowed_ebay_url(url):
4357
selectors = [
4458
'span[itemprop="price"]', # auction
4559
'span#prcIsum', # buy-it-now

0 commit comments

Comments
 (0)