-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathraw_walmart.py
More file actions
43 lines (42 loc) · 1.83 KB
/
raw_walmart.py
File metadata and controls
43 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from seleniumbase import SB
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.walmart.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)
sb.click('input[aria-label="Search"]')
sb.sleep(1.2)
search = "Settlers of Catan Board Game"
required_text = "Catan"
sb.press_keys('input[aria-label="Search"]', search + "\n")
sb.sleep(3.8)
if sb.is_element_visible("#px-captcha"):
sb.cdp.gui_click_and_hold("#px-captcha", 7.2)
sb.sleep(4.2)
if sb.is_element_visible("#px-captcha"):
sb.cdp.gui_click_and_hold("#px-captcha", 4.2)
sb.sleep(3.2)
sb.remove_elements('[data-testid="skyline-ad"]')
sb.remove_elements('[data-testid="sba-container"]')
print('*** Walmart Search for "%s":' % search)
print(' (Results must contain "%s".)' % required_text)
unique_item_text = []
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
items = sb.find_elements('[data-item-id]')
for item in items:
if required_text in item.text:
description = item.querySelector(
'[data-automation-id="product-title"]'
)
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
print("* " + description.text)
price = item.querySelector(
'[data-automation-id="product-price"]'
)
if price:
price_text = price.text
price_text = price_text.split("current price Now ")[-1]
price_text = price_text.split("current price ")[-1]
price_text = price_text.split(" ")[0]
print(" (" + price_text + ")")
sb.save_screenshot_to_logs()