DEV Community

Damilare Abogunrin
Damilare Abogunrin

Posted on

Exporting CSV Data from Real Estate Website with BS4

In this article, we will explore how to scrape data from a real estate website using Beautiful Soup version 4. Specifically, we will be scraping data on rental apartments in Amsterdam from www.pararius.com, one of the leading real estate websites in the Netherlands.

Using BS4, we will parse the HTML content of the webpage, extract relevant data such as apartment details, pricing, and location, and export it to CSV files for further analysis. This technical guide will provide step-by-step instructions on how to set up and execute a web scraping script using Python and BS4 to obtain and export data from real estate websites.

Packages

Beautiful Soup
Python CSV library
pip Installer

Script


from bs4 import BeautifulSoup

import requests

from csv import writer

url= "https://www.pararius.com/apartments/amsterdam?ac=1"

page = requests.get(url)

soup = BeautifulSoup(page.content, 'html.parser')

lists = soup.find_all('section', class_="listing-search-item")

with open('housing.csv', 'w', encoding='utf8', newline='') as f:

    thewriter = writer(f)

    header = ['Title', 'Location', 'Price', 'Area']

    thewriter.writerow(header)

    for list in lists:

        title = list.find('a', class_="listing-search-item__link--title").text.replace('\n', '')

        location = list.find('div', class_="listing-search-item__location").text.replace('\n', '')

        price = list.find('span', class_="listing-search-item__price").text.replace('\n', '')

        area = list.find('span', class_="illustrated-features__description").text.replace('\n', '')



        info = [title, location, price, area]

        thewriter.writerow(info)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)