from bs4 import BeautifulSoup
import requests
from csv import writer
def housing_d(page_no):
url = f"https://www.pararius.com/apartments/amsterdam/page-{page}"
web = requests.get(url) ## requesting url
html_code = web.content ## gives page contents
soup = BeautifulSoup(web.content, 'html.parser')
# print(soup.prettify) ## prettify will give html code in indent and proper way
web_page = soup.find_all('ul', class_="search-list")
with open('housing.csv', 'w', encoding='utf8', newline='') as f:
thewriter = writer(f)
header = ['Title', 'Location', 'Price', 'Area']
thewriter.writerow(header)
for division in web_page:
lists = division.find_all('li', class_="search-list__item search-list__item--listing")
for list in lists:
title = list.find('a', class_="listing-search-item__link--title").text.strip().replace('\n', '')
location = list.find('div', class_="listing-search-item__location").text.strip().replace('\n', '')
price = list.find('div', class_="listing-search-item__price").text.strip().replace('\n', '')
area = list.find('li', class_="illustrated-features__item illustrated-features__item--surface-area").text.strip().replace('\n', '')
info = [title, location, price, area]
thewriter.writerow(info)
return
for page in range(1,10):
housing_d(page)