Programming

Avto.net Scraper in Python: Car Prices, Mileage and Specs Past Cloudflare

Avto.net is Slovenia's biggest car marketplace: tens of thousands of used and new cars, each card with price, first registration, mileage, fuel, gearbox and engine. If you track used-car prices, compare dealers or build a valuation model for the Slovenian market, that is the dataset. Here is how to pull it into Python. The wall: a Cloudflare challenge A plain requests.get on avto.net returns HTTP 403 and a "Just a moment..." page. That is Cloudflare's JavaScript challenge: the page only appears

Avto.net is Slovenia's biggest car marketplace: tens of thousands of used and new cars, each card with price, first registration, mileage, fuel, gearbox and engine. If you track used-car prices, compare dealers or build a valuation model for the Slovenian market, that is the dataset. Here is how to pull it into Python.

The wall: a Cloudflare challenge

A plain requests.get on avto.net returns HTTP 403 and a "Just a moment..." page. That is Cloudflare's JavaScript challenge: the page only appears after a browser runs a script. Rotating IPs does not help, because the check is about running JavaScript, not about where the request comes from.

Through Scrape.do a plain request and a super=true request both came back as 502: the challenge still needs a browser. Adding render=true returned the real results page, HTTP 200 in about 3 seconds, for 5 credits.

The search URL needs all 80 fields

A short URL like results.asp?znamka=Volkswagen&model=Golf answers with "koda napake 005" (error code 005), and a page 2 built that way repeated page 1. The site's own pagination links send every search field, 80 of them, most at their defaults. Copy that set, change the make, model and stran (page), and pagination works.

What a result card holds

Each page has 48 cards, div.GO-Results-Row, server-rendered with no JSON to borrow:

  • Title in GO-Results-Naziv.
  • A small table with 1.registracija (first registration), Prevoženih (km driven), Gorivo (fuel), Menjalnik (gearbox) and Motor ("1968 ccm, 110 kW / 150 KM").
  • Price, in one of four shapes: a regular price; an old price struck through next to a discounted "AKCIJSKA CENA"; a regular price plus a "CENA S FINANCIRANJEM" (price with financing); or "Pokličite za ceno!" (call for price), which should become None, not 0.
  • Seller: dealers show a logo from /logotipi/<id>.gif; private sellers show a blank image.

Page 1 also carries promoted "TOP PONUDBA" cards. They are real listings, so keep them, but flag them.

The script

import csv
import html
import re
import time
from statistics import median
from urllib.parse import urlencode

import requests

TOKEN = "<your_token>"

# Every field the site's own pagination links send. With only a few of them
# Avto.net answers "koda napake 005".
DEFAULTS = (
    "znamka= model= modelID= tip= znamka2= model2= tip2= znamka3= model3= tip3= cenaMin=0 cenaMax=999999 "
    "letnikMin=0 letnikMax=2090 bencin=0 starost2=999 oblika=0 ccmMin=0 ccmMax=99999 mocMin=0 mocMax=999999 "
    "kmMin=0 kmMax=9999999 kwMin=0 kwMax=999 motortakt=0 motorvalji=0 lokacija=0 sirina=0 dolzina= dolzinaMIN=0 "
    "dolzinaMAX=100 nosilnostMIN=0 nosilnostMAX=999999 sedezevMIN=0 sedezevMAX=9 lezisc= presek=0 premer=0 col=0 "
    "vijakov=0 EToznaka=0 vozilo= airbag= barva= barvaint= doseg=0 BkType=0 BkOkvir=0 BkOkvirType=0 Bk4=0 "
    "EQ1=1000000000 EQ2=1000000000 EQ3=1000000000 EQ4=100000000 EQ5=1000000000 EQ6=1000000000 EQ7=1110100120 "
    "EQ8=1010000000 EQ9=1000000020 EQ10=1000000000 EQ11=1000000000 EQ12=122000000 KAT=1010000000 PIA= PIAzero= "
    "PIAOut= PSLO= akcija=0 paketgarancije= broker=0 prikazkategorije=0 kategorija=0 ONLvid=0 ONLnak=0 zaloga=10 "
    "arhiv=0 presort=3 tipsort=DESC stran=1"
)


def search_url(make, model="", page=1):
    params = dict(pair.split("=", 1) for pair in DEFAULTS.split())
    params.update(znamka=make, model=model, stran=str(page))
    return "https://www.avto.net/Ads/results.asp?" + urlencode(params)


def fetch(url):
    r = requests.get("https://api.scrape.do/",
                     params={"token": TOKEN, "url": url, "render": "true"}, timeout=150)
    if r.status_code != 200:
        raise RuntimeError(f"status {r.status_code}")
    page = r.text
    if "Ä" in page or "Ĺ" in page:  # UTF-8 read as windows-1250: "PrevoĹľenih"
        page = page.encode("cp1250").decode("utf-8")
    return page


def text(fragment):
    return re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", fragment or ""))).strip()


def number(value):
    digits = re.sub(r"\D", "", value or "")
    return int(digits) if digits else None


def parse(page):
    rows = []
    for card in page.split("GO-Results-Row")[1:]:
        found = re.search(r"details\.asp\?id=(\d+)", card)
        if not found:
            continue
        cells = dict((text(k), text(v)) for k, v in re.findall(
            r'<td class="[^"]*d-md-block[^"]*">([^<]+)</td>\s*<td[^>]*>(.*?)</td>', card, re.S))
        title = re.search(r'class="GO-Results-Naziv[^"]*"[^>]*>(.*?)</div>', card, re.S)
        regular = re.search(r'Price-TXT-Regular">([^<]+)<', card)
        old = re.search(r'Price-TXT-StaraCena">([^<]+)<', card)
        offer = re.search(r'Price-TXT-AkcijaCena">([^<]+)<', card)
        label = text((re.search(r'Price-Akcija-TXT">(.*?)</div>', card, re.S) or [None, ""])[1]).upper()
        financing = offer if offer and "FINANC" in label else None
        price = regular or (offer if offer and not financing else None)
        rows.append({
            "id": found.group(1),
            "title": text(title.group(1)) if title else "",
            "price_eur": number(price.group(1)) if price else None,
            "old_price_eur": number(old.group(1)) if old else None,
            "financing_eur": number(financing.group(1)) if financing else None,
            "year": number(cells.get("1.registracija")),
            "km": number(cells.get("Prevoženih")),
            "fuel": cells.get("Gorivo", ""),
            "gearbox": cells.get("Menjalnik", ""),
            "engine": cells.get("Motor", ""),
            "promoted": "GO-Results-Top-BadgeTop" in card,
            "seller": "dealer" if "/logotipi/" in card else "private",
            "url": "https://www.avto.net/Ads/details.asp?id=" + found.group(1),
        })
    return rows


def search(make, model="", max_pages=3):
    seen, out = set(), []
    for page in range(1, max_pages + 1):
        html_page = fetch(search_url(make, model, page))
        fresh = [r for r in parse(html_page) if r["id"] not in seen]
        if not fresh:
            break
        seen.update(r["id"] for r in fresh)
        out += fresh
        last = max([int(n) for n in re.findall(r'stran=(\d+)"', html_page)] or [page])
        if page >= last:
            break
        time.sleep(10)  # robots.txt: Crawl-delay: 10
    return out


cars = search("Volkswagen", "Golf", max_pages=3)
prices = [c["price_eur"] for c in cars if c["price_eur"]]
print(len(cars), "listings, median price", median(prices))
with open("golf.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.DictWriter(f, fieldnames=list(cars[0]))
    w.writeheader()
    w.writerows(cars)

render=true is the only parameter that matters here. Anything but a 200 stops the script, instead of parsing a challenge page as zero results.

What a live run looks like

Three pages of Volkswagen Golf took 3 requests (15 credits) and returned 144 listings: 6 promoted, 107 from dealers, 1 new car. Median price €13,555, median mileage 161,000 km, one "call for price". Each row is ready for a CSV:

{
  "id": "10000002",
  "title": "Examplewagen Golf 1.5 TSI",
  "price_eur": 21843,
  "old_price_eur": null,
  "financing_eur": 20400,
  "year": null,
  "km": null,
  "fuel": "bencinski motor",
  "gearbox": "avtomatski menjalnik",
  "engine": "1498 ccm, 110 kW / 150 KM",
  "promoted": false,
  "seller": "dealer"
}

(Field values above are from the package's fictional test fixture.)

Four things that will trip you up

Error 005. Send the full parameter set or the site refuses the search. It is not a block, just a picky form handler.

Double encoding. The site is windows-1250. Sometimes the rendered HTML arrives as UTF-8 bytes read as windows-1250, so "Prevoženih" turns into "PrevoĹľenih" and every label lookup misses. page.encode("cp1250").decode("utf-8") puts it back.

Four price shapes. A financing price is lower than the cash price and only applies with a loan. Keep it in its own column, or your medians drift down.

New cars. They show "Starost NOVO" and no first registration year. Keep year empty for them rather than guessing.

Listing pages

Each details.asp?id= page has a "basic data" table (th scope="row" / td): owners, inspection valid until, body type, doors, colour, location, combined consumption, emission class and CO2, plus the equipment list in ul.list blocks. The three Golf listings I opened had 99 to 121 equipment items each. Seller names and phone numbers are on that page too; leave them out.

Using it responsibly

Avto.net's robots.txt asks for Crawl-delay: 10, so the script waits 10 seconds between pages. Read the site's terms of use before any commercial or large-scale use, collect car data only (no seller names or phone numbers), and keep volumes modest. This is not legal advice.

Open-source package

The same logic, with price, year and mileage filters, listing pages, the encoding fix and a CLI, is on PyPI:

pip install avtonet-scraper
avtonet-scraper search Volkswagen Golf --pages 3 --price-max 20000 -f csv -o golf.csv

Source: github.com/bugrahansss/avtonet-scraper. No-code version: Avto.net Scraper on Apify. Demo: Hugging Face Space.

Run it at scale with Scrape.do

Every results page or listing is one rendered Scrape.do call: no headless browser to host, no challenge to solve, no proxy pool. 1,000 credits cover about 200 pages, close to 10,000 listings. Get 1000 free credits and start scraping with Scrape.do.