|
| 1 | +from seleniumbase import sb_cdp |
| 2 | + |
| 3 | +url = "https://www.walmart.com/" |
| 4 | +sb = sb_cdp.Chrome(url, locale="en", guest=True) |
| 5 | +sb.sleep(3) |
| 6 | +sb.click('input[aria-label="Search"]') |
| 7 | +sb.sleep(1.4) |
| 8 | +search = "Settlers of Catan Board Game" |
| 9 | +required_text = "Catan" |
| 10 | +sb.press_keys('input[aria-label="Search"]', search + "\n") |
| 11 | +sb.sleep(3.8) |
| 12 | +if sb.is_element_visible("#px-captcha"): |
| 13 | + sb.gui_click_and_hold("#px-captcha", 7.2) |
| 14 | + sb.sleep(4.2) |
| 15 | + if sb.is_element_visible("#px-captcha"): |
| 16 | + sb.gui_click_and_hold("#px-captcha", 4.2) |
| 17 | + sb.sleep(3.2) |
| 18 | +sb.remove_elements('[data-testid="skyline-ad"]') |
| 19 | +sb.remove_elements('[data-testid="sba-container"]') |
| 20 | +print('*** Walmart Search for "%s":' % search) |
| 21 | +print(' (Results must contain "%s".)' % required_text) |
| 22 | +unique_item_text = [] |
| 23 | +items = sb.find_elements('div[data-testid="list-view"]') |
| 24 | +for item in items: |
| 25 | + if required_text in item.text: |
| 26 | + description = item.querySelector( |
| 27 | + '[data-automation-id="product-title"]' |
| 28 | + ) |
| 29 | + if description and description.text not in unique_item_text: |
| 30 | + unique_item_text.append(description.text) |
| 31 | + print("* " + description.text) |
| 32 | + price = item.querySelector( |
| 33 | + '[data-automation-id="product-price"]' |
| 34 | + ) |
| 35 | + if price: |
| 36 | + price_text = price.text |
| 37 | + price_text = price_text.split("current price Now ")[-1] |
| 38 | + price_text = price_text.split("current price ")[-1] |
| 39 | + price_text = price_text.split(" ")[0] |
| 40 | + print(" (" + price_text + ")") |
| 41 | +sb.driver.stop() |
0 commit comments