-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapping_zeek.py
27 lines (26 loc) · 1007 Bytes
/
scrapping_zeek.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
from bs4 import BeautifulSoup
import csv
import requests
#Get zheky diraction
page = requests.get("https://kiev.vgorode.ua/reference/zheky/")
soup = BeautifulSoup(page.text, 'html.parser')
pages = soup.find(class_='list')
#Extract list of links
lis = pages.find_all('li')
#Create .csv file
f = csv.writer(open('ЖЭК инфо.csv', 'w'), delimiter=';')
f.writerow(['Город', 'Район', 'Адрес', 'Телефон'])
for item in range(len(lis)):
#Draw single url
url = lis[item].a['href'].split(',')[-2][1:-1]
info = requests.get(url)
local_soup = BeautifulSoup(info.text, 'html.parser')
block = local_soup.find(class_='cast')
data = block.find_all(class_='col-sm-8')
try:
f.writerow([data[0].get_text(), data[2].get_text(), data[1].get_text()[1:-1], data[3].get_text()])
except:
f.writerow([data[0].get_text(), data[1].get_text()[1:-1]])
print(item+1, "is not OK")
continue
print(item+1, 'ROW DONE!')