-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathraw_zoro.py
More file actions
33 lines (32 loc) · 1.28 KB
/
raw_zoro.py
File metadata and controls
33 lines (32 loc) · 1.28 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
from seleniumbase import SB
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.zoro.com/"
sb.activate_cdp_mode()
sb.open(url)
sb.sleep(1.2)
search_box = "input#searchInput"
search = "Flir Thermal Camera"
required_text = "Camera"
if not sb.is_element_present(search_box):
sb.evaluate("window.location.reload();")
sb.sleep(1.2)
sb.click(search_box)
sb.sleep(1.2)
sb.press_keys(search_box, search)
sb.sleep(0.6)
sb.click('button[data-za="searchButton"]')
sb.sleep(3.2)
sb.wait_for_element('[data-za="product-cards-list"]', timeout=5)
print('*** Zoro Search for "%s":' % search)
print(' (Results must contain "%s".)' % required_text)
unique_item_text = []
items = sb.find_elements('[data-za="search-product-card"]')
for item in items:
if required_text in item.text:
description = item.querySelector('[data-za="product-title"]')
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
print("* " + description.text)
price = item.querySelector("div.price-main")
if price:
print(" (" + price.text + ")")