Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,11 +48,21 @@ def scrape_booking_hotel():
|
|
48 |
name = name_elem.text.strip() if name_elem else "無資料"
|
49 |
price_elem = hotel.find('span', {'data-testid': 'price-and-discounted-price'})
|
50 |
price = price_elem.text.strip() if price_elem else "無資料"
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
rating_container = hotel.find('div', {'class': 'a3b8729ab1'})
|
53 |
rating_elem = rating_container.find('div', {'class': 'ac4a7896c7'}) if rating_container else None
|
54 |
rating = rating_elem.text.strip() if rating_elem else "無評分"
|
55 |
description_elem = hotel.find('div', {'data-testid': 'recommended-units'})
|
|
|
56 |
if description_elem:
|
57 |
room_type = description_elem.find('h4')
|
58 |
room_type = room_type.text.strip() if room_type else ""
|
@@ -65,6 +75,7 @@ def scrape_booking_hotel():
|
|
65 |
description = f"{room_type} | {bed_info} | {cancellation} | {payment}".strip(' |')
|
66 |
else:
|
67 |
description = "無說明"
|
|
|
68 |
hotels_data.append({
|
69 |
'飯店名稱': name,
|
70 |
'價格': price,
|
|
|
48 |
name = name_elem.text.strip() if name_elem else "無資料"
|
49 |
price_elem = hotel.find('span', {'data-testid': 'price-and-discounted-price'})
|
50 |
price = price_elem.text.strip() if price_elem else "無資料"
|
51 |
+
|
52 |
+
# 清洗價格資料
|
53 |
+
price = (
|
54 |
+
price.replace('TWD', '')
|
55 |
+
.replace(' ', '')
|
56 |
+
.replace(',', '')
|
57 |
+
.strip()
|
58 |
+
)
|
59 |
+
price = int(price) if price.isdigit() else None
|
60 |
+
|
61 |
rating_container = hotel.find('div', {'class': 'a3b8729ab1'})
|
62 |
rating_elem = rating_container.find('div', {'class': 'ac4a7896c7'}) if rating_container else None
|
63 |
rating = rating_elem.text.strip() if rating_elem else "無評分"
|
64 |
description_elem = hotel.find('div', {'data-testid': 'recommended-units'})
|
65 |
+
|
66 |
if description_elem:
|
67 |
room_type = description_elem.find('h4')
|
68 |
room_type = room_type.text.strip() if room_type else ""
|
|
|
75 |
description = f"{room_type} | {bed_info} | {cancellation} | {payment}".strip(' |')
|
76 |
else:
|
77 |
description = "無說明"
|
78 |
+
|
79 |
hotels_data.append({
|
80 |
'飯店名稱': name,
|
81 |
'價格': price,
|