-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelenium.py
59 lines (47 loc) · 1.71 KB
/
Selenium.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.options import Options
def save():
with open('2.txt', 'a', encoding="utf-8") as file:
file.write(f'{comp["title"]}@Price: {comp["price"]}@img: {comp["img"]}@description: {comp["description"]}\n')
def parse(line):
URL = line.strip()
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path=r"C:/test/geckodriver.exe")
driver.maximize_window()
WebDriverWait(driver,10)
driver.get(URL)
comps = []
try:
name = driver.find_elements_by_css_selector('p.b-product__price')
for names in name:
name = (names.text)
except:
pass
try:
price = driver.find_elements_by_css_selector('p.b-product__price')
for prices in price:
price = (prices.text)
except:
pass
description = driver.find_elements_by_css_selector('p.b-product__price')
for descriptions in description:
description = (descriptions.text)
imgsrc = driver.find_elements_by_css_selector('p.b-product__price')
for imgsrcs in imgsrc:
imgsrc = (imgsrcs.text)
comps.append({
'title': name,
'price': price,
'img': imgsrc,
'description': description
})
global comp
for comp in comps:
print(f'{comp["title"]} -> description: {comp["description"]} -> Price: {comp["price"]} -> img: {comp["img"]}')
save()
driver.quit()
with open("1.txt", "r", encoding="utf-8") as file1:
for line in file1:
parse (line)