Skip to content

Sample work · Data & Scraping

Data Extraction: 40 Businesses from an Online Directory into a Clean Table

Name, town, phone, website and opening hours of 40 car repair shops, read from a directory, cleaned and checked. With code, validation rules and the finished file.

Sample work, not a client job. The business and all figures are invented, so you can see what the work looks like before you order anything.

What is delivered

  • CSV file with 40 entries: name, town, phone, website, opening hours (Excel opens it directly)
  • Cleaned: phone numbers in one format, spaces and line breaks removed
  • Checked: no duplicates (name and town), no empty required fields
  • The script behind it, so the list can be updated later on your own

Download the CSV file

The CSV is the German original: its column headings are in German, the 40 entries are the ones described here.

The first six rows

NameTownPhoneOpening hours
Reifen BauerKlagenfurt+43 597 817838Mo-Fr 8:00-18:00
Kfz BauerLinz+43 578 641821Mo-Fr 8:00-18:00
Kfz WagnerKlagenfurt+43 513 602643Mo-Fr 8:00-18:00
Reifen HuberKlagenfurt+43 330 996445Mo-Do 7:00-16:30, Fr 7:00-12:00
Kfz LeitnerVillach+43 676 627415Mo-Fr 7:30-17:00
Kfz HoferKlagenfurt+43 304 515884Mo-Fr 8:00-18:00

How the data is read

First it is checked whether the site allows fetching in its robots.txt. Reading is slow, one page every three seconds, so the operator is not burdened. No personal data of private individuals is collected.

import time, requests
from urllib import robotparser
from bs4 import BeautifulSoup

BASE = "https://verzeichnis.example/kfz-werkstaetten?seite={}"

def allowed(url):
    rp = robotparser.RobotFileParser("https://verzeichnis.example/robots.txt"); rp.read()
    return rp.can_fetch("GLTools-Datenabruf", url)

def read(pages=4):
    rows = []
    for n in range(1, pages + 1):
        url = BASE.format(n)
        if not allowed(url):
            raise SystemExit("robots.txt forbids fetching - we stop here")
        html = requests.get(url, headers={"User-Agent": "GLTools-Datenabruf"}, timeout=30).text
        for card in BeautifulSoup(html, "html.parser").select(".eintrag"):
            rows.append({
                "name": card.select_one(".name").get_text(strip=True),
                "ort": card.select_one(".ort").get_text(strip=True),
                "telefon": card.select_one(".tel").get_text(strip=True),
            })
        time.sleep(3)          # read slowly: one page every 3 seconds
    return rows

Something like this for your business?

Describe briefly what you need. You get a fixed price before I start; nothing happens without your yes.

To the workshop