focus_de / scraping /README.md
SinclairSchneider's picture
Add detailed dataset card and the scraping pipeline used to build it
5bf8f7f verified
|
Raw History Blame Contribute Delete
3.15 kB
# How this dataset was built
| File | Purpose |
|---|---|
| [`crawler.py`](./crawler.py) | Distributed whole-site crawler for `www.focus.de`. Writes one JSON file per article to `pages/`. |
| [`finalize.ipynb`](./finalize.ipynb) | Merges `pages/*.json` into a single table, deduplicates it and pushes it to the Hub. |
| [`.env.example`](./.env.example) | Configuration template. Copy to `.env` and uncomment what you need. |
| [`proxies.example.txt`](./proxies.example.txt) | Proxy-list template for `SCRAPER_PROXY_FILE` — one proxy per line. |
```bash
pip install mechanicalsoup beautifulsoup4 lxml python-dateutil fake-useragent \
pandas datasets huggingface_hub tqdm
python crawler.py # writes pages/*.json; `touch killall.txt` to stop
jupyter notebook finalize.ipynb
```
## Configuration
All settings are optional and are read from the environment or from a `.env`
file next to `crawler.py`. The defaults are exactly the values used for the
original crawl.
```bash
cp .env.example .env # then uncomment what you need
```
| Variable | Meaning |
|---|---|
| `SCRAPER_PROXIES` | Inline proxy pool — entries separated by commas, semicolons, spaces or newlines. |
| `SCRAPER_PROXY_FILE` | Path to a file with **one proxy per line** — the practical form for a proxy farm. |
| `SCRAPER_THREADS` | Number of worker processes sharing the URL frontier. |
| `SCRAPER_TIMEOUT` | Socket timeout per request, in seconds. |
| `SCRAPER_RETRIES` | Attempts per URL before giving up. |
| `SCRAPER_START_URL` | Seed URL the crawl starts from. |
Environment variables take precedence over `.env`, so a single run can be
overridden on the command line:
```bash
SCRAPER_THREADS=4 python crawler.py
```
### Proxies
The original crawl connected directly, without proxies. A scheme is
optional on every entry (`http://` is assumed); one entry is picked per
request, so a pool spreads the load over several exits.
```bash
# a single proxy
export SCRAPER_PROXIES="proxy-a.example.com:3128"
# a small pool, rotated per request
export SCRAPER_PROXIES="proxy-a.example.com:3128,proxy-b.example.com:3128"
# with an explicit scheme and credentials
export SCRAPER_PROXIES="http://user:pass@proxy.example.com:3128"
# SOCKS, if PySocks is installed
export SCRAPER_PROXIES="socks5://localhost:9050"
```
For a **whole proxy farm**, keep the list in its own file — one proxy per line,
blank lines and `#` comments allowed — and point `SCRAPER_PROXY_FILE` at it.
The file can hold thousands of entries and be regenerated by another tool
without touching `.env` or the script:
```bash
cp proxies.example.txt proxies.txt # then fill in your own entries
echo 'SCRAPER_PROXY_FILE=proxies.txt' >> .env
python crawler.py
```
Leave both unset to crawl over a direct connection — that is the default and
what most of the crawls in this collection used.
The scripts contain no credentials, cookies or personal data.
Please crawl responsibly: honour `robots.txt` and the site's terms of use, keep
concurrency well below the 32 workers used here unless you have the operator's
permission, and prefer the published dataset over re-crawling.