|
| 1 | +from seleniumbase import SB |
| 2 | + |
| 3 | +with SB(uc=True, test=True, locale="en") as sb: |
| 4 | + url = "https://www.hilton.com/en/" |
| 5 | + sb.activate_cdp_mode(url) |
| 6 | + sb.sleep(4.5) |
| 7 | + location = "Sunnyvale, CA, USA" |
| 8 | + location_input = "input#location-input" |
| 9 | + sb.wait_for_element(location_input) |
| 10 | + sb.sleep(1.2) |
| 11 | + sb.click("input#location-input") |
| 12 | + sb.sleep(1.2) |
| 13 | + sb.press_keys("input#location-input", location) |
| 14 | + sb.sleep(2) |
| 15 | + sb.click('span:contains("Check-in")') |
| 16 | + sb.sleep(1.2) |
| 17 | + sb.click('button[aria-current="date"]') |
| 18 | + sb.sleep(1.2) |
| 19 | + sb.click('button[data-testid="shop-modal-done-cta"]') |
| 20 | + sb.sleep(1.5) |
| 21 | + sb.click('button[data-testid="search-submit-button"]') |
| 22 | + sb.sleep(6.5) |
| 23 | + sb.reconnect() |
| 24 | + for window in sb.driver.window_handles: |
| 25 | + sb.switch_to_window(window) |
| 26 | + if "/search/" in sb.get_current_url(): |
| 27 | + break |
| 28 | + hotel_card = 'li[data-testid*="hotel-card"]' |
| 29 | + hotel_cards = sb.select_all(hotel_card) |
| 30 | + print("Hilton Hotels in %s:" % location) |
| 31 | + if not hotel_cards: |
| 32 | + print("No availability over the selected dates!") |
| 33 | + css = "css selector" # Reconnected Selenium - Using WebElement API |
| 34 | + for i, card in enumerate(hotel_cards): |
| 35 | + hotel = card.find_element(css, 'h3[data-testid*="PropertyName"]') |
| 36 | + price = card.find_element(css, 'p[data-testid="rateItem"]') |
| 37 | + if hotel and price: |
| 38 | + print("* %s: %s => %s" % ( |
| 39 | + i + 1, hotel.text.strip(), price.text.strip()) |
| 40 | + ) |
0 commit comments