|
| 1 | +from seleniumbase import SB |
| 2 | + |
| 3 | +with SB(uc=True, test=True, locale_code="en") as sb: |
| 4 | + url = "www.elal.com/flight-deals/en-us/flights-from-boston-to-tel-aviv" |
| 5 | + sb.activate_cdp_mode(url) |
| 6 | + sb.sleep(2) |
| 7 | + sb.cdp.click('button[data-att="search"]') |
| 8 | + sb.sleep(4) |
| 9 | + sb.cdp.click_if_visible("#onetrust-close-btn-container button") |
| 10 | + sb.sleep(0.5) |
| 11 | + view_other_dates = 'button[aria-label*="viewOtherDates.cta"]' |
| 12 | + if sb.cdp.is_element_visible(view_other_dates): |
| 13 | + sb.cdp.click(view_other_dates) |
| 14 | + sb.sleep(4.5) |
| 15 | + if sb.is_element_visible("flexible-search-calendar"): |
| 16 | + print("*** Flight Calendar for El Al (Boston to Tel Aviv): ***") |
| 17 | + print(sb.cdp.get_text("flexible-search-calendar")) |
| 18 | + prices = [] |
| 19 | + elements = sb.cdp.find_elements("span.matric-cell__content__price") |
| 20 | + if elements: |
| 21 | + print("*** Prices List: ***") |
| 22 | + for element in elements: |
| 23 | + prices.append(element.text) |
| 24 | + for price in sorted(prices): |
| 25 | + print(price) |
| 26 | + print("*** Lowest Price: ***") |
| 27 | + lowest_price = sorted(prices)[0] |
| 28 | + print(lowest_price) |
| 29 | + sb.cdp.find_element_by_text(lowest_price).click() |
| 30 | + sb.sleep(1) |
| 31 | + search_cell = 'button[aria-label*="Search.cell.buttonTitle"]' |
| 32 | + sb.cdp.scroll_into_view(search_cell) |
| 33 | + sb.sleep(1) |
| 34 | + sb.cdp.click(search_cell) |
| 35 | + sb.sleep(5) |
| 36 | + else: |
| 37 | + elements = sb.cdp.find_elements("div.ui-bound__price__value") |
| 38 | + print("*** Lowest Prices: ***") |
| 39 | + first = True |
| 40 | + for element in elements: |
| 41 | + if "lowest price" in element.text: |
| 42 | + if first: |
| 43 | + print("Departure Flight:") |
| 44 | + print(element.text) |
| 45 | + first = False |
| 46 | + else: |
| 47 | + print("Return Flight:") |
| 48 | + print(element.text) |
| 49 | + break |
| 50 | + dates = sb.cdp.find_elements('div[class*="flight-date"]') |
| 51 | + if len(dates) == 2: |
| 52 | + print("*** Departure Date: ***") |
| 53 | + print(dates[0].text) |
| 54 | + print("*** Return Date: ***") |
| 55 | + print(dates[1].text) |
0 commit comments