-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (25 loc) · 942 Bytes
/
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
import requests
from bs4 import BeautifulSoup
import csv
url = 'https://www.morizon.pl/mieszkania/warszawa/praga-poludnie/?ps%5Bowner%5D%5B0%5D=4'
urls_response = requests.get(url)
soup = BeautifulSoup(urls_response.text, 'html.parser')
soup_links = soup.find_all('a', class_='property_link property-url')
links = []
numbers = []
with open('morizon_links.csv', 'w') as morizon_links:
writer = csv.writer(morizon_links)
for soup_link in soup_links:
writer.writerow([soup_link['href']])
links.append(soup_link['href'])
for link in links:
url2 = link
urls_response = requests.get(url2)
soup = BeautifulSoup(urls_response.text, 'html.parser')
soup_links = soup.find_all('span', class_='phone hidden')
numbers.append(soup_links[0].text)
with open('morizon_links2.csv', 'w') as morizon_links2:
writer = csv.writer(morizon_links2)
for number in numbers:
writer.writerow([number])
print(numbers)