-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
37 lines (27 loc) · 1.06 KB
/
Copy pathscrape.py
File metadata and controls
37 lines (27 loc) · 1.06 KB
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
#import requests
from bs4 import BeautifulSoup
import json
from urllib import request
def fetch_apartments(page_number):
url = f"https://www.turek.net.pl/ogloszenia/nieruchomosci/page-{
page_number}"
# response = requests.get(url)
response = request.urlopen(url).read().decode('UTF-8')
soup = BeautifulSoup(response, 'html.parser')
apartments = []
apartment_elements = soup.find_all(
'div', class_='announcement-list--body')
for apartment in apartment_elements:
title = apartment.find('header').find('h2').text
description = apartment.find(
'div', class_='announcement-list--description').text
value = apartment.find(
'div', class_='announcement-list--attributes').find_all('span')[5].text
date = apartment.find(
'div', class_='announcement-list--attributes').find_all('span')[9].text
if ("sprzedam mieszkanie" in title.lower()):
print(title, value, date, description)
def main():
fetch_apartments(1)
if __name__ == "__main__":
main()