Metadata-Version: 2.4
Name: lacentrale-pros-scraper
Version: 0.1.0
Summary: Scrape La Centrale's dealer directory (pros.lacentrale.fr): French car dealers, SIREN/SIRET, opening hours and every vehicle in stock with Python.
Author: Buğrahan Saka
License-Expression: MIT
Project-URL: Homepage, https://github.com/bugrahansss/lacentrale-pros-scraper
Project-URL: Source, https://github.com/bugrahansss/lacentrale-pros-scraper
Project-URL: Issues, https://github.com/bugrahansss/lacentrale-pros-scraper/issues
Keywords: lacentrale,la centrale,pros.lacentrale.fr,car dealers,used cars,france,web scraping,scraper,scrapedo
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25
Dynamic: license-file

# La Centrale Pros Scraper

[![PyPI](https://img.shields.io/pypi/v/lacentrale-pros-scraper)](https://pypi.org/project/lacentrale-pros-scraper/)
[![Python](https://img.shields.io/pypi/pyversions/lacentrale-pros-scraper)](https://pypi.org/project/lacentrale-pros-scraper/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)

Scrape [La Centrale's](https://www.lacentrale.fr) dealer directory and dealer pages ([pros.lacentrale.fr](https://pros.lacentrale.fr)) into structured data. List every car dealer in a **city, department, region or brand network**, open a dealer for its **SIREN and SIRET, founding year, verified badge, address with coordinates, opening hours, website and stock size**, and pull **every vehicle in its stock**: make, model, version, year, mileage, fuel, gearbox, price, monthly price, La Centrale's **deal rating** (very good, good, fair, bad), warranty and listing dates. JSON or CSV.

```bash
pip install lacentrale-pros-scraper
export SCRAPEDO_TOKEN=your_token
lacentrale-pros --city lyon -f csv -o lyon_dealers.csv          # directory cards
lacentrale-pros --city lyon --details -o lyon_dealers.json      # + SIREN/SIRET, hours, website
lacentrale-pros --city lyon --stock -f csv -o lyon_cars.csv     # every car of every dealer
lacentrale-pros C045088 --stock -o stock.json                   # one dealer
```

## Why plain requests fail

```python
import requests

r = requests.get("https://pros.lacentrale.fr/C045088")
print(r.status_code)   # 403
print(r.text[:200])    # ... Please enable JS and disable any ad blocker ... dd={'rt':'c' ...
```

lacentrale.fr is protected by DataDome, which answers a script with `403` and a JavaScript challenge. This package sends each request through [Scrape.do](https://scrape.do/?utm_source=github&utm_medium=readme&utm_campaign=lacentrale-pros-scraper), which returns the real page. A plain request is enough, no extra parameters: **1 credit per page**.

## Where the data is

* **Directory** (`www.lacentrale.fr/annuaire/garages-villes/<city>`, `garages-departements/<dept>`, `garages-regions/<region>`, `marques/<brand>`, `?page=N&perPage=20`): server-rendered cards with the dealer name, postcode and city, number of ads, a "Marques" badge for franchised dealers, and the dealer reference (`C` + 6 digits) in `data-tracking-meta`. Some dealers link to their own website instead of their La Centrale page, but the reference is still there.
* **Dealer page** (`pros.lacentrale.fr/C045088`):
  * an `AutoDealer` JSON-LD block with name, address and coordinates. Its `openingHoursSpecification` is a **JSON string inside the JSON**: decode it a second time.
  * an identity card ("Vendeur vérifié", "Date de création", "Stock"; big groups show "Stock national" instead).
  * a footer with **SIREN / SIRET** and the dealer's website.
  * `window.__PRELOADED_STATE_LISTING__`, whose `search.hits` is the first page of stock (9 vehicles) and `search.total` the stock size.
* **More stock**: `pros.lacentrale.fr/C045088/index?options=&page=2&vertical=car`, same state object.

In a live test, Lyon had 17 dealers in the directory and 228 cars in stock, scraped for 37 credits. 42 of those cars carried La Centrale's "very good deal" badge and 52 "good deal"; the median price was €28,940.

## Python

```python
from lacentrale_pros import LaCentralePros

lc = LaCentralePros(token="YOUR_SCRAPEDO_TOKEN")   # or set SCRAPEDO_TOKEN

for card in lc.directory("city", "Lyon"):
    print(card.ref, card.name, card.postcode, card.ads)

dealer, cars = lc.dealer_with_stock("C045088")
print(dealer.name, dealer.siret, dealer.founded, dealer.opening_hours)
for car in cars:
    print(car.make, car.model, car.year, car.mileage, car.price, car.deal)
print(lc.credits_used)
```

## Fields

**Directory card:** `ref`, `name`, `postcode`, `city`, `ads`, `franchise`, `url`, `own_site`.

**Dealer:** `ref`, `url`, `name`, `dealer_type` (`CONCESSIONNAIRE`, `CENTRE_MULTIMARQUES`, ...), `verified`, `founded`, `stock`, `stock_national`, `street`, `postcode`, `city`, `country`, `latitude`, `longitude`, `opening_hours`, `siren`, `siret`, `website`, `phone`.

**Vehicle:** `reference`, `url`, `make`, `model`, `version`, `year`, `mileage`, `energy`, `gearbox`, `category`, `color`, `doors`, `price`, `monthly_from`, `deal` (`VERY_GOOD_DEAL`, `GOOD_DEAL`, `EQUITABLE_DEAL`, `BAD_DEAL`, `NOT_COMPUTED`), `warranty_months`, `first_online`, `last_update`, `department`, `pictures`, `photo`, `is_new`, `dealer_ref`, `dealer_name`.

## Use it responsibly

This is business data published by professional sellers. Some dealers are sole traders, so treat names and phone numbers as personal data under the GDPR: use them for legitimate purposes, honour objection requests, and respect La Centrale's terms. Don't republish vehicle photos. This is not legal advice.

## Tests

```bash
PYTHONPATH=src python -m unittest discover -s tests
```

The fixtures are fictional ("GARAGE EXEMPLE LYON", example.com).

## License

MIT
