-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (53 loc) · 1.79 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
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
60
61
62
63
64
65
66
67
68
69
70
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import csv
driver = webdriver.Chrome()
driver.implicitly_wait(10)
zavodpt_link = 'https://zavod-pt.ru/'
list = []
with open('list.csv', 'r') as file:
reader = csv.reader(file, delimiter=';')
for row in reader:
list.append(' '.join(row))
print(list)
def link_crawling():
driver.get(url=zavodpt_link)
driver.maximize_window()
link_crawling_list = []
for article in list:
try:
link_crawling_list_row = []
find_field = driver.find_element(By.ID, 'title-search-input_fixed')
find_field.click()
find_field.send_keys(article)
find_field.send_keys(Keys.ENTER)
#time.sleep(3)
h1_text = driver.find_element(By.ID, 'pagetitle').text
link_crawling_list_row.append(h1_text)
link_crawling_list_row.append(article)
link_crawling_list_row.append(driver.current_url)
link_crawling_list.append(link_crawling_list_row)
print(f'Status №{list.index(article)} is ok from {len(list)}')
print(link_crawling_list_row)
driver.get(url=zavodpt_link)
except Exception as ex:
link_crawling_list.append(link_crawling_list_row)
print(ex)
driver.get(url=zavodpt_link)
#time.sleep(1)
continue
with open('result.csv', 'w') as f:
writer = csv.writer(f, delimiter=';', lineterminator='\n')
for item in link_crawling_list:
writer.writerow(item)
return
try:
link_crawling()
except Exception as ex:
print(ex)
pass
finally:
print('Done')
driver.close()
driver.quit()