Skip to content

Commit

Permalink
Add new CDP Mode examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmintz committed Nov 5, 2024
1 parent 7acd1ff commit 7fadabd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/cdp_mode/raw_nordstrom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from seleniumbase import SB

with SB(uc=True, test=True, locale_code="en") as sb:
url = "https://www.nordstrom.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.2)
sb.cdp.click("input#keyword-search-input")
sb.sleep(0.8)
search = "cocktail dresses for women teal"
sb.cdp.press_keys("input#keyword-search-input", search + "\n")
sb.sleep(2.2)
for i in range(16):
sb.cdp.scroll_down(16)
sb.sleep(0.16)
print('*** Nordstrom Search for "%s":' % search)
unique_item_text = []
items = sb.cdp.find_elements("article")
for item in items:
description = item.querySelector("article h3")
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
price_text = ""
price = item.querySelector('div div span[aria-hidden="true"]')
if price:
price_text = price.text
print("* %s (%s)" % (description.text, price_text))
33 changes: 33 additions & 0 deletions examples/cdp_mode/raw_southwest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from seleniumbase import SB

with SB(uc=True, test=True, locale_code="en") as sb:
url = "https://www.southwest.com/air/booking/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)
origin = "DEN"
destination = "PHX"
sb.cdp.gui_click_element("input#originationAirportCode")
sb.sleep(0.2)
sb.uc_gui_press_keys(origin + "\n")
sb.sleep(0.5)
sb.cdp.gui_click_element("h1.heading")
sb.sleep(0.5)
sb.cdp.gui_click_element("input#destinationAirportCode")
sb.sleep(0.2)
sb.uc_gui_press_keys(destination + "\n")
sb.sleep(0.5)
sb.cdp.gui_click_element("h1.heading")
sb.sleep(0.5)
sb.cdp.click('form button[aria-label*="Search"]')
sb.sleep(4)
day = sb.cdp.get_text('[aria-current="true"] span[class*="cal"]')
print("**** Flights from %s to %s ****" % (origin, destination))
flights = sb.find_elements("li.air-booking-select-detail")
for flight in flights:
info = flight.text
departs = info.split("Departs")[-1].split("M")[0].strip() + "M"
arrives = info.split("Arrives")[-1].split("M")[0].strip() + "M"
stops = flight.query_selector(".flight-stops-badge").text
duration = flight.query_selector('[class*="flight-duration"]').text
price = flight.query_selector('span.currency span[aria-hidden]').text
print(f"* {day}, {departs} -> {arrives} ({stops}: {duration}) {price}")

0 comments on commit 7fadabd

Please sign in to comment.