-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (28 loc) · 1.06 KB
/
main.py
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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
driver = webdriver.Firefox()
driver.get('https://rozetka.com.ua')
def func(search_string, threshold = 5):
search_fields = driver.find_elements(By.XPATH, "//input[@type='text'][@name='search']")
assert len(search_fields) == 1
if search_fields[0].text != "":
search_fields[0].clear()
search_fields[0].send_keys(search_string)
buttons = driver.find_elements(By.XPATH, "//form/button")
assert len(buttons) == 1
buttons[0].click()
time.sleep(15)
items = driver.find_elements(By.XPATH, "//rz-grid/ul/li")
filtered_items = []
for item in items:
comment_amount_spans = item.find_elements(By.XPATH, ".//rz-rating-review-block/a/span")
assert len(comment_amount_spans) == 1
try:
n_comments = int(comment_amount_spans[0].text)
except:
n_comments = 0
if n_comments >= threshold:
filtered_items.append(item)
return filtered_items