Add detailed dataset card and the scraping pipeline used to build it
Browse files- README.md +374 -14
- scraping/.env.example +52 -0
- scraping/README.md +83 -0
- scraping/crawler.py +369 -0
- scraping/finalize.ipynb +200 -0
- scraping/proxies.example.txt +15 -0
README.md
CHANGED
|
@@ -1,4 +1,41 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
dataset_info:
|
| 3 |
features:
|
| 4 |
- name: title
|
|
@@ -23,17 +60,340 @@ dataset_info:
|
|
| 23 |
num_examples: 742
|
| 24 |
download_size: 2721103
|
| 25 |
dataset_size: 4685901
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
pretty_name: EUobserver (euobserver.com)
|
| 5 |
+
size_categories:
|
| 6 |
+
- n<1K
|
| 7 |
+
task_categories:
|
| 8 |
+
- text-generation
|
| 9 |
+
- text-classification
|
| 10 |
+
- summarization
|
| 11 |
+
- feature-extraction
|
| 12 |
+
tags:
|
| 13 |
+
- brussels
|
| 14 |
+
- english
|
| 15 |
+
- eu-affairs
|
| 16 |
+
- investigative-journalism
|
| 17 |
+
- journalism
|
| 18 |
+
- media
|
| 19 |
+
- media-bias
|
| 20 |
+
- news
|
| 21 |
+
- news-articles
|
| 22 |
+
- non-profit-media
|
| 23 |
+
- research-only
|
| 24 |
+
- text-and-data-mining
|
| 25 |
+
- web-scraping
|
| 26 |
+
annotations_creators:
|
| 27 |
+
- no-annotation
|
| 28 |
+
language_creators:
|
| 29 |
+
- found
|
| 30 |
+
multilinguality:
|
| 31 |
+
- monolingual
|
| 32 |
+
source_datasets:
|
| 33 |
+
- original
|
| 34 |
+
configs:
|
| 35 |
+
- config_name: default
|
| 36 |
+
data_files:
|
| 37 |
+
- split: train
|
| 38 |
+
path: data/train-*
|
| 39 |
dataset_info:
|
| 40 |
features:
|
| 41 |
- name: title
|
|
|
|
| 60 |
num_examples: 742
|
| 61 |
download_size: 2721103
|
| 62 |
dataset_size: 4685901
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
# EUobserver (euobserver.com)
|
| 66 |
+
|
| 67 |
+
**742 English-language news articles** crawled from
|
| 68 |
+
[`euobserver.com`](https://euobserver.com) and published as a Hugging Face dataset.
|
| 69 |
+
This is part of the [International Newspapers collection](https://huggingface.co/collections/SinclairSchneider/international-newspapers-6900fdd5083089f336574c82),
|
| 70 |
+
a set of comparable corpora covering English-language newspapers and EU-affairs outlets, all built with the same crawler and the same
|
| 71 |
+
extraction pipeline so that they can be compared and combined directly.
|
| 72 |
+
|
| 73 |
+
> ## ⚠️ For scientific research only
|
| 74 |
+
>
|
| 75 |
+
> This corpus is published **exclusively for scientific research** under the German
|
| 76 |
+
> research exception for text and data mining — the *Forschungsprivileg* of
|
| 77 |
+
> **§ 60d UrhG** (implementing Art. 3 of EU Directive 2019/790). The article texts remain
|
| 78 |
+
> the copyright of their publisher and are **not** licensed for commercial use,
|
| 79 |
+
> redistribution, or republication. By downloading it you confirm that you use it for
|
| 80 |
+
> non-commercial scientific research. See [Licensing and intended use](#licensing-and-intended-use).
|
| 81 |
+
>
|
| 82 |
+
> The articles are reproduced verbatim from the publisher's website; their content expresses
|
| 83 |
+
> the views of that publisher, not of the dataset author.
|
| 84 |
+
|
| 85 |
+
## At a glance
|
| 86 |
+
|
| 87 |
+
| | |
|
| 88 |
+
|---|---|
|
| 89 |
+
| **Source** | [`euobserver.com`](https://euobserver.com) |
|
| 90 |
+
| **Rows** | 742 |
|
| 91 |
+
| **Columns** | 8 (`title`, `content`, `author`, `description`, `keywords`, `category`, `datePublished`, `url`) |
|
| 92 |
+
| **Language** | English (`en`) |
|
| 93 |
+
| **Split** | `train` (single split) |
|
| 94 |
+
| **Format** | Parquet, 1 shard, ≈ 3 MB download / 4 MB in memory |
|
| 95 |
+
| **Intended use** | Scientific research only (*Forschungsprivileg*, § 60d UrhG) |
|
| 96 |
+
| **Mirror** | [`NLP-UniBW/euobserver_com`](https://huggingface.co/datasets/NLP-UniBW/euobserver_com) |
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from datasets import load_dataset
|
| 100 |
+
|
| 101 |
+
ds = load_dataset("SinclairSchneider/euobserver_com", split="train")
|
| 102 |
+
print(ds[0]["title"])
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## About the source
|
| 106 |
+
|
| 107 |
+
[EUobserver](https://euobserver.com/) is a Brussels-based online newspaper reporting on
|
| 108 |
+
European Union affairs. Founded in 2000 by Lisbeth Kirk, it is run as a non-profit and has
|
| 109 |
+
historically positioned itself as an independent, institution-critical counterweight to the
|
| 110 |
+
Brussels press corps, financed through a mix of subscriptions, foundation grants and donations. Its
|
| 111 |
+
newsroom is small, so output volume is far lower than the other outlets in this collection.
|
| 112 |
+
|
| 113 |
+
## Dataset structure
|
| 114 |
+
|
| 115 |
+
Single `train` split with 742 rows and the following columns:
|
| 116 |
+
|
| 117 |
+
| Column | Type | Description | Extracted from |
|
| 118 |
+
|---|---|---|---|
|
| 119 |
+
| `title` | `string` | Headline of the article. | `<meta property="og:title">` |
|
| 120 |
+
| `content` | `string` | Full plain-text body of the article. | all `<span style="white-space: pre-wrap;">` blocks except the final two, space-joined |
|
| 121 |
+
| `author` | `string` | Author(s) as published by the outlet. | the second-to-last `<span style="white-space: pre-wrap;">` block |
|
| 122 |
+
| `description` | `string` | Teaser / meta description of the article. | `<meta name="description">` |
|
| 123 |
+
| `keywords` | `list[string]` | Topic keywords / tags assigned by the publisher. | the underlined tag `<div>`s next to the `<h1>` |
|
| 124 |
+
| `category` | `string` | Section the article was published in. | the first path segment of the article URL |
|
| 125 |
+
| `datePublished` | `string` | Publication timestamp. | `<meta property="article:published_time">` |
|
| 126 |
+
| `url` | `string` | Canonical URL the article was fetched from. | the crawled URL |
|
| 127 |
+
|
| 128 |
+
### Example record
|
| 129 |
+
|
| 130 |
+
```json
|
| 131 |
+
{
|
| 132 |
+
"title": "Behind the scam: how an alleged criminal network set a trap for thousands of Europeans to fall for ‘fake’ investments and raked in millions",
|
| 133 |
+
"content": "At first glance, Olympus Prime looked more like a thriving tech start-up than one of the numerous, non-descript call centres popping up across Serbia’s capital city. Housed in a high-spec design building amongst a growing business neighborhood in Belgrade, the company shared space with a Chinese cultural complex and an upscale hotel. Yet when Serbian police entered the premises of the Olympus Prim …",
|
| 134 |
+
"author": "Meanwhile, many victims still grapple with what happened to them. Some of those approached for this investigation refused to speak, afraid they might be targeted by scam agencies again. For others, the memories were simply too painful to revisit. \"It is the worst thing to talk about,\" says one woman who lost €54,000 to Greenfields Capital, “because as a victim, you are trying to forget it.”",
|
| 135 |
+
"description": "A suspected scam network operating out of Serbia duped an estimated 70,000 people worldwide into making bogus investments, profiting €250m in the process. The transnational scheme involved a former Premier League team sponsor and a convicted money launderer, Investigate Europe and the Balkan Investigative Reporting Network can reveal, in the first part of our Scam Europe series. ",
|
| 136 |
+
"keywords": [
|
| 137 |
+
"EU & the World",
|
| 138 |
+
"Investigations",
|
| 139 |
+
"Health & Society"
|
| 140 |
+
],
|
| 141 |
+
"category": "eu-and-the-world",
|
| 142 |
+
"datePublished": "2025-09-30T06:00:00.000Z",
|
| 143 |
+
"url": "https://euobserver.com/eu-and-the-world/arf605a31b"
|
| 144 |
+
}
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Temporal coverage
|
| 148 |
+
|
| 149 |
+
The `datePublished` column could be parsed for **742 of 742** rows (100.0 %). Those rows span **2023-01-02 → 2025-10-28**.
|
| 150 |
+
|
| 151 |
+
| Year | Articles | |
|
| 152 |
+
|---:|---:|:---|
|
| 153 |
+
| 2023 | 1 | `█` |
|
| 154 |
+
| 2024 | 233 | `███████████` |
|
| 155 |
+
| 2025 | 508 | `████████████████████████` |
|
| 156 |
+
|
| 157 |
+
## How the data was collected
|
| 158 |
+
|
| 159 |
+
The whole pipeline is contained in this repository under [`scraping/`](./scraping) and consists
|
| 160 |
+
of two steps: a distributed crawler that walks the site and writes one JSON file per article, and
|
| 161 |
+
a consolidation notebook that merges those files into the dataset you are reading.
|
| 162 |
+
|
| 163 |
+
### 1. Crawling — [`scraping/crawler.py`](./scraping/crawler.py)
|
| 164 |
+
|
| 165 |
+
The crawler is a breadth-first whole-site crawler built on
|
| 166 |
+
[MechanicalSoup](https://mechanicalsoup.readthedocs.io/) and `multiprocessing`:
|
| 167 |
+
|
| 168 |
+
1. **Sharded frontier.** 32 worker processes each own one `multiprocessing.Manager().Queue()`.
|
| 169 |
+
A URL is assigned to a worker by `int(md5(url).hexdigest(), 16) % 32`, so every URL is always
|
| 170 |
+
handled by the same worker and no locking or cross-process deduplication is needed.
|
| 171 |
+
2. **Seed.** The crawl is seeded with a single article URL
|
| 172 |
+
(`https://euobserver.com/digital/ar9b098635`) and discovers
|
| 173 |
+
everything else by following links.
|
| 174 |
+
3. **Link discovery.** Every fetched page is parsed with BeautifulSoup/lxml; all `<a href>` values
|
| 175 |
+
that start with `https://euobserver.com` or with `/` (which are then made absolute) are added to the
|
| 176 |
+
frontier. URLs containing `#` are dropped.
|
| 177 |
+
4. **URL filtering.** Before fetching, a URL is skipped when it contains `/files/`, `/video/`,
|
| 178 |
+
`.jpg`, `.pdf`, `.xml`, `.pptx`, `.shtml` or `.epub`, or when it has fewer than five path
|
| 179 |
+
segments (which filters out section index pages).
|
| 180 |
+
5. **Fetching.** Each URL gets up to 10 attempts with a 10 s timeout.
|
| 181 |
+
6. **Extraction.** `get_content()` turns the HTML into a record (see below). Only pages with a
|
| 182 |
+
non-empty `content` are written out, as `pages/<flattened-url>.json`.
|
| 183 |
+
7. **Resumability.** Each worker appends every known and every visited URL to
|
| 184 |
+
`data/thread_<id>_pages.txt` and `data/thread_<id>_pages_visited.txt`, and re-reads them on
|
| 185 |
+
start, so an interrupted crawl continues where it stopped. Creating a file named `killall.txt`
|
| 186 |
+
in the working directory stops all workers cleanly.
|
| 187 |
+
|
| 188 |
+
Crawler settings used for this site:
|
| 189 |
+
|
| 190 |
+
- **Worker processes:** 32 (`iNumberOfThreads = 32`)
|
| 191 |
+
- **Retries per URL:** 10, with a 10-second socket timeout per attempt
|
| 192 |
+
- **Proxy pool:** used — requests were sent through a rotating pool of forward proxies (the published script reproduces this via `SCRAPER_PROXIES`, see below)
|
| 193 |
+
- **User-agent rotation:** yes, a random UA per request via `fake_useragent`
|
| 194 |
+
- **Politeness delay:** none — throttling was handled by the proxy pool / retry loop
|
| 195 |
+
- **Bot-challenge handling:** responses containing `#challenge-error-text` or `You don't have permission to access` are discarded and retried after a short pause
|
| 196 |
+
- **Raw HTML dump:** enabled (`raw/`), used for debugging the parser
|
| 197 |
+
|
| 198 |
+
**Paywall handling.** Articles showing the subscriber notice `To read this story, log in or subscribe` in an `<h4>` are skipped.
|
| 199 |
+
|
| 200 |
+
### 2. Article extraction
|
| 201 |
+
|
| 202 |
+
`get_content()` reads the fields from the page's JSON-LD (`<script type="application/ld+json">`)
|
| 203 |
+
and/or its HTML, as follows:
|
| 204 |
+
|
| 205 |
+
| Field | Source in the page |
|
| 206 |
+
|---|---|
|
| 207 |
+
| `title` | `<meta property="og:title">` |
|
| 208 |
+
| `content` | all `<span style="white-space: pre-wrap;">` blocks except the final two, space-joined |
|
| 209 |
+
| `author` | the second-to-last `<span style="white-space: pre-wrap;">` block |
|
| 210 |
+
| `description` | `<meta name="description">` |
|
| 211 |
+
| `keywords` | the underlined tag `<div>`s next to the `<h1>` |
|
| 212 |
+
| `category` | the first path segment of the article URL |
|
| 213 |
+
| `datePublished` | `<meta property="article:published_time">` |
|
| 214 |
+
| `url` | the crawled URL |
|
| 215 |
+
|
| 216 |
+
EUobserver's CMS renders the article body as a flat run of
|
| 217 |
+
`white-space: pre-wrap` spans whose last two entries are the byline and a trailing notice. The
|
| 218 |
+
parser therefore takes everything except the final two spans as the body and the second-to-last
|
| 219 |
+
span as the author.
|
| 220 |
+
|
| 221 |
+
Each article is stored as a JSON file of the shape
|
| 222 |
+
|
| 223 |
+
```json
|
| 224 |
+
{
|
| 225 |
+
"title": "…",
|
| 226 |
+
"content": "…",
|
| 227 |
+
"additional_attributes": { "author": "…", "description": "…", "keywords": "…", "category": "…", "datePublished": "…", "url": "…" }
|
| 228 |
+
}
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
### 3. Consolidation — [`scraping/finalize.ipynb`](./scraping/finalize.ipynb)
|
| 232 |
+
|
| 233 |
+
1. `glob("pages/*.json")` collects every article file.
|
| 234 |
+
2. The nested records are flattened into one `pandas.DataFrame` column per field.
|
| 235 |
+
3. `df.drop_duplicates(subset=['title'])` removes duplicates — the same article is often reachable
|
| 236 |
+
under several URLs (print/mobile variants, tracking parameters, section mirrors), and
|
| 237 |
+
the headline is the most reliable identity key available.
|
| 238 |
+
4. The frame is written to `euobserver_com.json` and pushed with
|
| 239 |
+
`datasets.Dataset.from_pandas(df).push_to_hub("SinclairSchneider/euobserver_com")`.
|
| 240 |
+
|
| 241 |
+
### Dataset-specific notes
|
| 242 |
+
|
| 243 |
+
- **This is a small dataset.** The positional span heuristic above only matches EUobserver's current article template, and subscriber-only stories are skipped, so coverage is a fraction of the site's archive.
|
| 244 |
+
- `author` and `category` are positional/URL-derived rather than read from structured metadata, so they are noisier than in the other datasets of this collection.
|
| 245 |
+
|
| 246 |
+
### Reproducing the crawl
|
| 247 |
+
|
| 248 |
+
```bash
|
| 249 |
+
pip install mechanicalsoup beautifulsoup4 lxml python-dateutil fake-useragent \
|
| 250 |
+
pandas datasets huggingface_hub tqdm
|
| 251 |
+
|
| 252 |
+
mkdir euobserver_com && cd euobserver_com
|
| 253 |
+
curl -L -O https://huggingface.co/datasets/SinclairSchneider/euobserver_com/resolve/main/scraping/crawler.py
|
| 254 |
+
|
| 255 |
+
python crawler.py # writes pages/*.json; `touch killall.txt` to stop
|
| 256 |
+
jupyter notebook finalize.ipynb
|
| 257 |
+
```
|
| 258 |
+
|
| 259 |
+
#### Routing the crawl through your own proxies
|
| 260 |
+
|
| 261 |
+
The original crawl ran behind a pool of forward proxies on a private network. Those addresses are
|
| 262 |
+
infrastructure-specific and have been **removed** from the published script. Instead, `crawler.py`
|
| 263 |
+
reads the `SCRAPER_PROXIES` environment variable: a comma-separated list of proxies, written with
|
| 264 |
+
or without a scheme (`http://` is assumed when none is given). One entry is picked per request, so
|
| 265 |
+
a pool spreads the load across several exits.
|
| 266 |
+
|
| 267 |
+
```bash
|
| 268 |
+
# a single proxy
|
| 269 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128"
|
| 270 |
+
|
| 271 |
+
# a pool, rotated per request
|
| 272 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128,proxy-b.example.com:3128"
|
| 273 |
+
|
| 274 |
+
# with an explicit scheme and credentials
|
| 275 |
+
export SCRAPER_PROXIES="http://user:pass@proxy.example.com:3128"
|
| 276 |
+
|
| 277 |
+
# SOCKS, if PySocks is installed
|
| 278 |
+
export SCRAPER_PROXIES="socks5://localhost:9050"
|
| 279 |
+
|
| 280 |
+
# back to a direct connection — this is the default
|
| 281 |
+
unset SCRAPER_PROXIES
|
| 282 |
+
|
| 283 |
+
python crawler.py
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
Internally this becomes `requests`' standard `{'http': …, 'https': …}` proxy mapping; with the
|
| 287 |
+
variable unset the mapping is empty and the crawler connects directly. No credentials, cookies or
|
| 288 |
+
personal data are contained in the published code.
|
| 289 |
+
|
| 290 |
+
**Please crawl responsibly:** respect `robots.txt` and the site's terms of use, keep the
|
| 291 |
+
concurrency far below the 32 workers used here unless you have the site's permission, and prefer
|
| 292 |
+
this published dataset over re-crawling.
|
| 293 |
+
|
| 294 |
+
## Usage
|
| 295 |
+
|
| 296 |
+
```python
|
| 297 |
+
from datasets import load_dataset
|
| 298 |
+
import pandas as pd
|
| 299 |
+
|
| 300 |
+
ds = load_dataset("SinclairSchneider/euobserver_com", split="train")
|
| 301 |
+
|
| 302 |
+
# stream instead of downloading everything
|
| 303 |
+
stream = load_dataset("SinclairSchneider/euobserver_com", split="train", streaming=True)
|
| 304 |
+
print(next(iter(stream))["title"])
|
| 305 |
+
|
| 306 |
+
# as a DataFrame
|
| 307 |
+
df = ds.to_pandas()
|
| 308 |
+
df["datePublished"] = pd.to_datetime(df["datePublished"], errors="coerce", utc=True, format="mixed")
|
| 309 |
+
recent = df[df["datePublished"].dt.year >= 2024]
|
| 310 |
+
print(len(recent), "articles from 2024 onwards")
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
Combining several outlets into one comparative corpus:
|
| 314 |
+
|
| 315 |
+
```python
|
| 316 |
+
from datasets import load_dataset, concatenate_datasets
|
| 317 |
+
|
| 318 |
+
outlets = ["SinclairSchneider/euobserver_com", "SinclairSchneider/tagesschau_de"]
|
| 319 |
+
parts = []
|
| 320 |
+
for name in outlets:
|
| 321 |
+
d = load_dataset(name, split="train").select_columns(["title", "content", "url"])
|
| 322 |
+
parts.append(d.add_column("outlet", [name.split("/")[-1]] * len(d)))
|
| 323 |
+
corpus = concatenate_datasets(parts)
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
## Limitations and biases
|
| 327 |
+
|
| 328 |
+
- **Crawl, not archive.** Coverage is whatever was reachable by following links from the seed URL
|
| 329 |
+
at crawl time. Articles that were deleted, depublished or orphaned before the crawl are missing,
|
| 330 |
+
and old content is covered less densely than recent content.
|
| 331 |
+
- **Free content only.** Paywalled articles were deliberately skipped, so the dataset under-represents long-form and investigative pieces, which are the ones most often placed behind the paywall.
|
| 332 |
+
- **Deduplication by headline.** Two genuinely different articles with an identical headline
|
| 333 |
+
(common for recurring formats such as weather or daily briefings) collapse into one row.
|
| 334 |
+
- **Noisy metadata.** `author`, `category` and `keywords` come straight from the publisher's markup,
|
| 335 |
+
which changed over the years; empty strings are common and category labels are not harmonised
|
| 336 |
+
across outlets.
|
| 337 |
+
- **Editorial perspective.** This is the output of a single outlet. Any model trained on it alone
|
| 338 |
+
inherits that outlet's selection of topics, framing and vocabulary — which is exactly why the
|
| 339 |
+
collection provides the same pipeline across the political spectrum.
|
| 340 |
+
- **No text normalisation.** Bodies are the concatenated paragraphs as published, including
|
| 341 |
+
typographic quotes, soft hyphens and occasional residual boilerplate.
|
| 342 |
+
|
| 343 |
+
## Licensing and intended use
|
| 344 |
+
|
| 345 |
+
### Scientific research only — *Forschungsprivileg* (§ 60d UrhG)
|
| 346 |
+
|
| 347 |
+
This dataset is made available **solely for the purpose of scientific research**. The legal basis
|
| 348 |
+
is the German text-and-data-mining exception for research, the so-called **Forschungsprivileg**:
|
| 349 |
+
|
| 350 |
+
- **§ 60d UrhG** — *Text und Data Mining für Zwecke der wissenschaftlichen Forschung* — allows
|
| 351 |
+
research organisations to make reproductions of lawfully accessible works in order to carry out
|
| 352 |
+
text and data mining for **non-commercial** scientific research, and to share the resulting
|
| 353 |
+
corpus with a specifically limited circle of people for joint research and with individual third
|
| 354 |
+
parties for the purpose of quality assurance.
|
| 355 |
+
- It implements **Art. 3 of Directive (EU) 2019/790** (the DSM Directive); comparable research
|
| 356 |
+
exceptions exist in the other EU member states.
|
| 357 |
+
- § 60d UrhG does **not** cover commercial exploitation. Research organisations that give a
|
| 358 |
+
commercial enterprise preferential access are explicitly excluded from the privilege.
|
| 359 |
+
|
| 360 |
+
### What this means for you
|
| 361 |
+
|
| 362 |
+
✅ **Permitted** — using the corpus for non-commercial scientific research: text and data mining,
|
| 363 |
+
corpus linguistics, media-bias and discourse analysis, training and evaluating research models,
|
| 364 |
+
reproducing published findings, and quality checks by individual third parties.
|
| 365 |
+
|
| 366 |
+
❌ **Not permitted** — commercial use or commercial model training; redistributing or republishing
|
| 367 |
+
the article texts; presenting the texts as your own; building products or services on the article
|
| 368 |
+
texts; any use that substitutes for reading the publisher's own website.
|
| 369 |
+
|
| 370 |
+
The **article texts remain the copyright of EUobserver and its publisher.** No licence to them is
|
| 371 |
+
granted or implied by this repository. Only the crawling and extraction code in `scraping/` is
|
| 372 |
+
offered for free reuse.
|
| 373 |
+
|
| 374 |
+
If your intended use falls outside the research exception, obtain permission from the rights
|
| 375 |
+
holder, or use only the derived, non-expressive data (statistics, embeddings, counts). Note that
|
| 376 |
+
§ 60d UrhG also expects research corpora to be deleted once they are no longer needed for the
|
| 377 |
+
research purpose, with archiving permitted at trusted institutions.
|
| 378 |
+
|
| 379 |
+
If you are a rights holder and want content removed, please open a discussion on this repository.
|
| 380 |
+
|
| 381 |
+
> This section is an orientation for researchers, not legal advice. Responsibility for your own
|
| 382 |
+
> use of the data remains with you and your institution.
|
| 383 |
+
|
| 384 |
+
## Citation
|
| 385 |
+
|
| 386 |
+
```bibtex
|
| 387 |
+
@misc{euobserver_com_dataset,
|
| 388 |
+
title = {EUobserver (euobserver.com): a corpus of German news articles},
|
| 389 |
+
author = {Schneider, Sinclair},
|
| 390 |
+
year = {2025},
|
| 391 |
+
howpublished = {Hugging Face},
|
| 392 |
+
url = {https://huggingface.co/datasets/SinclairSchneider/euobserver_com}
|
| 393 |
+
}
|
| 394 |
+
```
|
| 395 |
+
|
| 396 |
+
## See also
|
| 397 |
+
|
| 398 |
+
- The full [International Newspapers collection](https://huggingface.co/collections/SinclairSchneider/international-newspapers-6900fdd5083089f336574c82)
|
| 399 |
+
- Mirror of this dataset: [`NLP-UniBW/euobserver_com`](https://huggingface.co/datasets/NLP-UniBW/euobserver_com)
|
scraping/.env.example
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ---------------------------------------------------------------------------
|
| 2 |
+
# crawler.py configuration for euobserver.com
|
| 3 |
+
#
|
| 4 |
+
# Copy this file to `.env` and uncomment the lines you need:
|
| 5 |
+
#
|
| 6 |
+
# cp .env.example .env
|
| 7 |
+
#
|
| 8 |
+
# Variables that are already set in the real environment take precedence over
|
| 9 |
+
# this file, so a single run can still be overridden on the command line:
|
| 10 |
+
#
|
| 11 |
+
# SCRAPER_THREADS=4 python crawler.py
|
| 12 |
+
#
|
| 13 |
+
# Everything here is optional - the defaults shown are exactly the values that
|
| 14 |
+
# were used for the original crawl.
|
| 15 |
+
# ---------------------------------------------------------------------------
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# === Proxies ===============================================================
|
| 19 |
+
|
| 20 |
+
# Inline pool. Separate entries with commas, semicolons, spaces or newlines.
|
| 21 |
+
# A scheme is optional - "http://" is assumed when none is given. One entry is
|
| 22 |
+
# picked per request, so several entries spread the load over several exits.
|
| 23 |
+
#SCRAPER_PROXIES=proxy-a.example.com:3128,proxy-b.example.com:3128
|
| 24 |
+
|
| 25 |
+
# ... with an explicit scheme and credentials:
|
| 26 |
+
#SCRAPER_PROXIES=http://user:pass@proxy.example.com:3128
|
| 27 |
+
|
| 28 |
+
# ... SOCKS (requires PySocks):
|
| 29 |
+
#SCRAPER_PROXIES=socks5://localhost:9050
|
| 30 |
+
|
| 31 |
+
# For a whole proxy farm, keep the list in its own file instead: one proxy per
|
| 32 |
+
# line, blank lines and "#" comments allowed. See `proxies.example.txt`.
|
| 33 |
+
# This scales to thousands of entries and can be regenerated by another tool
|
| 34 |
+
# without ever touching this file. Both settings may be combined.
|
| 35 |
+
#SCRAPER_PROXY_FILE=proxies.txt
|
| 36 |
+
|
| 37 |
+
# Leave both unset to crawl over a direct connection - that is the default.
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# === Crawler tuning ========================================================
|
| 41 |
+
|
| 42 |
+
# Number of worker processes sharing the URL frontier.
|
| 43 |
+
#SCRAPER_THREADS=32
|
| 44 |
+
|
| 45 |
+
# Socket timeout per request, in seconds.
|
| 46 |
+
#SCRAPER_TIMEOUT=10.0
|
| 47 |
+
|
| 48 |
+
# Attempts per URL before it is given up on.
|
| 49 |
+
#SCRAPER_RETRIES=10
|
| 50 |
+
|
| 51 |
+
# Seed URL the crawl starts from. Any article URL on the site works.
|
| 52 |
+
#SCRAPER_START_URL=https://euobserver.com/digital/ar9b098635
|
scraping/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# How this dataset was built
|
| 2 |
+
|
| 3 |
+
| File | Purpose |
|
| 4 |
+
|---|---|
|
| 5 |
+
| [`crawler.py`](./crawler.py) | Distributed whole-site crawler for `euobserver.com`. Writes one JSON file per article to `pages/`. |
|
| 6 |
+
| [`finalize.ipynb`](./finalize.ipynb) | Merges `pages/*.json` into a single table, deduplicates it and pushes it to the Hub. |
|
| 7 |
+
| [`.env.example`](./.env.example) | Configuration template. Copy to `.env` and uncomment what you need. |
|
| 8 |
+
| [`proxies.example.txt`](./proxies.example.txt) | Proxy-list template for `SCRAPER_PROXY_FILE` — one proxy per line. |
|
| 9 |
+
|
| 10 |
+
```bash
|
| 11 |
+
pip install mechanicalsoup beautifulsoup4 lxml python-dateutil fake-useragent \
|
| 12 |
+
pandas datasets huggingface_hub tqdm
|
| 13 |
+
|
| 14 |
+
python crawler.py # writes pages/*.json; `touch killall.txt` to stop
|
| 15 |
+
jupyter notebook finalize.ipynb
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
## Configuration
|
| 19 |
+
|
| 20 |
+
All settings are optional and are read from the environment or from a `.env`
|
| 21 |
+
file next to `crawler.py`. The defaults are exactly the values used for the
|
| 22 |
+
original crawl.
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
cp .env.example .env # then uncomment what you need
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
| Variable | Meaning |
|
| 29 |
+
|---|---|
|
| 30 |
+
| `SCRAPER_PROXIES` | Inline proxy pool — entries separated by commas, semicolons, spaces or newlines. |
|
| 31 |
+
| `SCRAPER_PROXY_FILE` | Path to a file with **one proxy per line** — the practical form for a proxy farm. |
|
| 32 |
+
| `SCRAPER_THREADS` | Number of worker processes sharing the URL frontier. |
|
| 33 |
+
| `SCRAPER_TIMEOUT` | Socket timeout per request, in seconds. |
|
| 34 |
+
| `SCRAPER_RETRIES` | Attempts per URL before giving up. |
|
| 35 |
+
| `SCRAPER_START_URL` | Seed URL the crawl starts from. |
|
| 36 |
+
|
| 37 |
+
Environment variables take precedence over `.env`, so a single run can be
|
| 38 |
+
overridden on the command line:
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
SCRAPER_THREADS=4 python crawler.py
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### Proxies
|
| 45 |
+
|
| 46 |
+
The original crawl ran behind a pool of forward proxies on a private network.
|
| 47 |
+
Those addresses have been removed from this published copy. A scheme is
|
| 48 |
+
optional on every entry (`http://` is assumed); one entry is picked per
|
| 49 |
+
request, so a pool spreads the load over several exits.
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
# a single proxy
|
| 53 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128"
|
| 54 |
+
|
| 55 |
+
# a small pool, rotated per request
|
| 56 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128,proxy-b.example.com:3128"
|
| 57 |
+
|
| 58 |
+
# with an explicit scheme and credentials
|
| 59 |
+
export SCRAPER_PROXIES="http://user:pass@proxy.example.com:3128"
|
| 60 |
+
|
| 61 |
+
# SOCKS, if PySocks is installed
|
| 62 |
+
export SCRAPER_PROXIES="socks5://localhost:9050"
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
For a **whole proxy farm**, keep the list in its own file — one proxy per line,
|
| 66 |
+
blank lines and `#` comments allowed — and point `SCRAPER_PROXY_FILE` at it.
|
| 67 |
+
The file can hold thousands of entries and be regenerated by another tool
|
| 68 |
+
without touching `.env` or the script:
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
cp proxies.example.txt proxies.txt # then fill in your own entries
|
| 72 |
+
echo 'SCRAPER_PROXY_FILE=proxies.txt' >> .env
|
| 73 |
+
python crawler.py
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Leave both unset to crawl over a direct connection — that is the default and
|
| 77 |
+
what most of the crawls in this collection used.
|
| 78 |
+
|
| 79 |
+
The scripts contain no credentials, cookies or personal data.
|
| 80 |
+
|
| 81 |
+
Please crawl responsibly: honour `robots.txt` and the site's terms of use, keep
|
| 82 |
+
concurrency well below the 32 workers used here unless you have the operator's
|
| 83 |
+
permission, and prefer the published dataset over re-crawling.
|
scraping/crawler.py
ADDED
|
@@ -0,0 +1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Whole-site crawler for euobserver.com (EUobserver).
|
| 3 |
+
|
| 4 |
+
This is the exact script that produced the Hugging Face dataset
|
| 5 |
+
https://huggingface.co/datasets/SinclairSchneider/euobserver_com — see that dataset card for a
|
| 6 |
+
step-by-step description of the pipeline.
|
| 7 |
+
|
| 8 |
+
Overview
|
| 9 |
+
--------
|
| 10 |
+
* 32 worker processes share the URL frontier; a URL is routed to a worker by
|
| 11 |
+
``int(md5(url).hexdigest(), 16) % 32`` so that no locking is required.
|
| 12 |
+
* The crawl is seeded with one article URL and discovers everything else by
|
| 13 |
+
following links below ``https://euobserver.com``.
|
| 14 |
+
* ``get_content()`` turns an article page into a record; pages with an empty
|
| 15 |
+
body are dropped. Each surviving article is written to
|
| 16 |
+
``pages/<flattened-url>.json``.
|
| 17 |
+
* Known and visited URLs are appended to ``data/thread_<id>_pages*.txt``, so an
|
| 18 |
+
interrupted crawl resumes where it left off. Create a file named
|
| 19 |
+
``killall.txt`` in the working directory to stop all workers cleanly.
|
| 20 |
+
|
| 21 |
+
Usage
|
| 22 |
+
-----
|
| 23 |
+
pip install mechanicalsoup beautifulsoup4 lxml python-dateutil fake-useragent
|
| 24 |
+
python crawler.py
|
| 25 |
+
|
| 26 |
+
Configuration
|
| 27 |
+
-------------
|
| 28 |
+
Copy ``.env.example`` to ``.env`` and uncomment what you need - proxies, worker
|
| 29 |
+
count, timeout, retries and the seed URL are all read from there (environment
|
| 30 |
+
variables still win over the file). For a large proxy farm put one proxy per
|
| 31 |
+
line into a text file and point ``SCRAPER_PROXY_FILE`` at it; see
|
| 32 |
+
``proxies.example.txt``. The private proxy addresses used in the original crawl
|
| 33 |
+
have been removed from this published copy.
|
| 34 |
+
|
| 35 |
+
Please crawl responsibly: honour robots.txt and the site's terms of use, and
|
| 36 |
+
lower the worker count unless you have the operator's permission.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
import hashlib
|
| 40 |
+
import multiprocessing
|
| 41 |
+
import mechanicalsoup
|
| 42 |
+
|
| 43 |
+
from bs4 import BeautifulSoup
|
| 44 |
+
import re
|
| 45 |
+
import json
|
| 46 |
+
import os
|
| 47 |
+
import io
|
| 48 |
+
import time
|
| 49 |
+
import random
|
| 50 |
+
from fake_useragent import UserAgent
|
| 51 |
+
|
| 52 |
+
from dateutil.parser import parse
|
| 53 |
+
|
| 54 |
+
base_url = "https://euobserver.com"
|
| 55 |
+
|
| 56 |
+
# --- Configuration ---------------------------------------------------------
|
| 57 |
+
# Every setting below can be supplied through the environment or through a
|
| 58 |
+
# ".env" file placed next to this script. Copy ".env.example" to ".env" and
|
| 59 |
+
# uncomment what you need:
|
| 60 |
+
#
|
| 61 |
+
# cp .env.example .env
|
| 62 |
+
#
|
| 63 |
+
# Nothing has to be set - the defaults are exactly the values that were used
|
| 64 |
+
# for the original crawl.
|
| 65 |
+
def _load_dotenv(path=".env"):
|
| 66 |
+
"""Read a ".env" file: KEY=VALUE per line, "#" starts a comment.
|
| 67 |
+
|
| 68 |
+
Variables that are already set in the real environment win, so a single run
|
| 69 |
+
can still be overridden with e.g. ``SCRAPER_THREADS=4 python crawler.py``.
|
| 70 |
+
"""
|
| 71 |
+
if not os.path.isfile(path):
|
| 72 |
+
return
|
| 73 |
+
with io.open(path, "r", encoding="utf-8") as handle:
|
| 74 |
+
for line in handle:
|
| 75 |
+
line = line.strip()
|
| 76 |
+
if not line or line.startswith("#") or "=" not in line:
|
| 77 |
+
continue
|
| 78 |
+
key, _, value = line.partition("=")
|
| 79 |
+
key = key.strip()
|
| 80 |
+
value = value.strip().strip('"').strip("'")
|
| 81 |
+
if key and key not in os.environ:
|
| 82 |
+
os.environ[key] = value
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
_load_dotenv()
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _load_proxy_pool():
|
| 89 |
+
"""Build the proxy pool from SCRAPER_PROXIES and/or SCRAPER_PROXY_FILE.
|
| 90 |
+
|
| 91 |
+
SCRAPER_PROXIES inline list; entries separated by commas, semicolons,
|
| 92 |
+
spaces or newlines.
|
| 93 |
+
SCRAPER_PROXY_FILE path to a file holding one proxy per line, with blank
|
| 94 |
+
lines and "#" comments allowed. This is the practical
|
| 95 |
+
form for a whole proxy farm: the pool can be swapped or
|
| 96 |
+
regenerated without touching the script or the .env.
|
| 97 |
+
|
| 98 |
+
Both may be combined. Entries may be written with or without a scheme
|
| 99 |
+
("http://" is assumed when none is given). Duplicates are dropped and an
|
| 100 |
+
empty pool simply means "connect directly".
|
| 101 |
+
"""
|
| 102 |
+
raw = os.environ.get("SCRAPER_PROXIES", "")
|
| 103 |
+
proxy_file = os.environ.get("SCRAPER_PROXY_FILE", "").strip()
|
| 104 |
+
if proxy_file:
|
| 105 |
+
if not os.path.isfile(proxy_file):
|
| 106 |
+
raise SystemExit("SCRAPER_PROXY_FILE points to a missing file: " + proxy_file)
|
| 107 |
+
with io.open(proxy_file, "r", encoding="utf-8") as handle:
|
| 108 |
+
raw = raw + "\n" + handle.read()
|
| 109 |
+
cleaned = []
|
| 110 |
+
for line in raw.splitlines():
|
| 111 |
+
line = line.split("#", 1)[0].strip()
|
| 112 |
+
if line:
|
| 113 |
+
cleaned.append(line)
|
| 114 |
+
pool = []
|
| 115 |
+
for entry in re.split(r"[,;\s]+", " ".join(cleaned)):
|
| 116 |
+
entry = entry.strip()
|
| 117 |
+
if not entry:
|
| 118 |
+
continue
|
| 119 |
+
if "://" not in entry:
|
| 120 |
+
entry = "http://" + entry
|
| 121 |
+
if entry not in pool:
|
| 122 |
+
pool.append(entry)
|
| 123 |
+
return pool
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
PROXY_POOL = _load_proxy_pool()
|
| 127 |
+
NUM_THREADS = int(os.environ.get("SCRAPER_THREADS", "32"))
|
| 128 |
+
REQUEST_TIMEOUT = float(os.environ.get("SCRAPER_TIMEOUT", "10.0"))
|
| 129 |
+
MAX_RETRIES = int(os.environ.get("SCRAPER_RETRIES", "10"))
|
| 130 |
+
START_URL = os.environ.get("SCRAPER_START_URL", "https://euobserver.com/digital/ar9b098635")
|
| 131 |
+
|
| 132 |
+
def log(number, url):
|
| 133 |
+
if not os.path.isdir("log"):
|
| 134 |
+
os.mkdir("log")
|
| 135 |
+
with open("log"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 136 |
+
f.write(url)
|
| 137 |
+
|
| 138 |
+
def error(number, url):
|
| 139 |
+
if not os.path.isdir("error"):
|
| 140 |
+
os.mkdir("error")
|
| 141 |
+
with open("error"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 142 |
+
f.write(url)
|
| 143 |
+
|
| 144 |
+
def raw(number, url, page_str):
|
| 145 |
+
if not os.path.isdir("raw"):
|
| 146 |
+
os.mkdir("raw")
|
| 147 |
+
with open("raw"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 148 |
+
f.write(url)
|
| 149 |
+
f.write(page_str)
|
| 150 |
+
|
| 151 |
+
def get_content(url, page_str):
|
| 152 |
+
additional_attributes = {
|
| 153 |
+
'author':'',
|
| 154 |
+
'description':'',
|
| 155 |
+
'keywords':'',
|
| 156 |
+
'category':'',
|
| 157 |
+
'datePublished':'',
|
| 158 |
+
'url':'',
|
| 159 |
+
}
|
| 160 |
+
dict_return = {'content':'', 'title':'', 'additional_attributes': additional_attributes}
|
| 161 |
+
|
| 162 |
+
if page_str=="":
|
| 163 |
+
return dict_return
|
| 164 |
+
|
| 165 |
+
page_bs = BeautifulSoup(page_str, "lxml")
|
| 166 |
+
|
| 167 |
+
pro_article = "To read this story, log in or subscribe" in [x.text for x in page_bs.find_all("h4")]
|
| 168 |
+
|
| 169 |
+
if pro_article:
|
| 170 |
+
return dict_return
|
| 171 |
+
|
| 172 |
+
title = page_bs.find("meta", {'property':'og:title'}).get('content', '') if page_bs.find("meta", {'property':'og:title'}) != None else ""
|
| 173 |
+
content = " ".join([x.text.strip() for x in page_bs.find_all("span", {'style':'white-space: pre-wrap;'})][:-2]) if page_bs.find("span", {'style':'white-space: pre-wrap;'}) != None else ""
|
| 174 |
+
author = [x.text.strip() for x in page_bs.find_all("span", {'style':'white-space: pre-wrap;'})] if page_bs.find("span", {'style':'white-space: pre-wrap;'}) != None else ""
|
| 175 |
+
author = author[-2] if len(author) > 1 else ""
|
| 176 |
+
description = page_bs.find("meta", {'name':'description'}).get('content') if page_bs.find("meta", {'name':'description'}) != None else ""
|
| 177 |
+
keywords = [x.text for x in page_bs.find("h1").parent.find_all("div") if "underline" in x.get('style', '')] if page_bs.find("h1") != None else []
|
| 178 |
+
category = url.split("/")[3] if len(url.split("/")) > 3 else ""
|
| 179 |
+
datePublished = page_bs.find("meta", {'property':'article:published_time'}).get('content', '') if page_bs.find("meta", {'property':'article:published_time'}) != None else ""
|
| 180 |
+
|
| 181 |
+
additional_attributes = {
|
| 182 |
+
'author':author,
|
| 183 |
+
'description':description,
|
| 184 |
+
'keywords':keywords,
|
| 185 |
+
'category':category,
|
| 186 |
+
'datePublished':datePublished,
|
| 187 |
+
'url':url,
|
| 188 |
+
}
|
| 189 |
+
dict_return = {'content':content, 'title':title, 'additional_attributes': additional_attributes}
|
| 190 |
+
return dict_return
|
| 191 |
+
|
| 192 |
+
def get_urls(page_str):
|
| 193 |
+
return_urls = set()
|
| 194 |
+
page_bs = BeautifulSoup(page_str, "lxml")
|
| 195 |
+
for tag in page_bs.findAll("a", href=True):
|
| 196 |
+
url = tag.get("href", '')
|
| 197 |
+
if "#" in url:
|
| 198 |
+
continue
|
| 199 |
+
if url.startswith(base_url):
|
| 200 |
+
return_urls.add(url)
|
| 201 |
+
if url.startswith("/"):
|
| 202 |
+
url = base_url + url
|
| 203 |
+
return_urls.add(url)
|
| 204 |
+
return return_urls
|
| 205 |
+
|
| 206 |
+
def readSavedData(iId, sPageset, sPagesetVisited):
|
| 207 |
+
if not os.path.isdir("data"):
|
| 208 |
+
os.mkdir("data")
|
| 209 |
+
if os.path.isfile("data/thread_"+str(iId)+"_pages.txt"):
|
| 210 |
+
with io.open("data/thread_"+str(iId)+"_pages.txt", "r", encoding="utf-8") as f:
|
| 211 |
+
for line in f:
|
| 212 |
+
if "#" in line:
|
| 213 |
+
continue
|
| 214 |
+
line = line.replace("\n", "")
|
| 215 |
+
if line != "":
|
| 216 |
+
sPageset.add(line)
|
| 217 |
+
|
| 218 |
+
if os.path.isfile("data/thread_"+str(iId)+"_pages_visited.txt"):
|
| 219 |
+
with io.open("data/thread_"+str(iId)+"_pages_visited.txt", "r", encoding="utf-8") as f:
|
| 220 |
+
for line in f:
|
| 221 |
+
if "#" in line:
|
| 222 |
+
continue
|
| 223 |
+
line = line.replace("\n", "")
|
| 224 |
+
if line != "":
|
| 225 |
+
sPagesetVisited.add(line)
|
| 226 |
+
|
| 227 |
+
def addStartChannel(sPage, iNumberOfThreads, lQueues):
|
| 228 |
+
iIndex = int(hashlib.md5(sPage.encode("utf")).hexdigest(),16)%iNumberOfThreads
|
| 229 |
+
lQueues[iIndex].put(sPage)
|
| 230 |
+
|
| 231 |
+
def getNextPage(lQueues, iId, sPageset, sPagesetVisited):
|
| 232 |
+
while True:
|
| 233 |
+
if os.path.isfile("killall.txt"):
|
| 234 |
+
return None
|
| 235 |
+
|
| 236 |
+
while not lQueues[iId].empty():
|
| 237 |
+
sPage = lQueues[iId].get()
|
| 238 |
+
iLenBefore = len(sPageset)
|
| 239 |
+
sPageset.add(sPage)
|
| 240 |
+
iLenAfter = len(sPageset)
|
| 241 |
+
if iLenBefore != iLenAfter:
|
| 242 |
+
with io.open("data/thread_"+str(iId)+"_pages.txt", "a", encoding="utf-8") as f:
|
| 243 |
+
if sPage != "" and sPage != "\t":
|
| 244 |
+
f.write(sPage + "\n")
|
| 245 |
+
sPagesetToVisit = sPageset - sPagesetVisited
|
| 246 |
+
|
| 247 |
+
if len(sPagesetToVisit) != 0:
|
| 248 |
+
sPage = list(sPagesetToVisit)[0]
|
| 249 |
+
return sPage
|
| 250 |
+
else:
|
| 251 |
+
print("Thread " + str(iId) + " is waiting")
|
| 252 |
+
time.sleep(3)
|
| 253 |
+
|
| 254 |
+
def addPagesToVisit(sPages, iNumberOfThreads, lQueues):
|
| 255 |
+
for sPage in sPages:
|
| 256 |
+
if sPage != "":
|
| 257 |
+
iIndex = int(hashlib.md5(sPage.encode("utf")).hexdigest(), 16) % iNumberOfThreads
|
| 258 |
+
lQueues[iIndex].put(sPage)
|
| 259 |
+
|
| 260 |
+
def addVisitedPages(sPage, sPagesetsetVisited, iId):
|
| 261 |
+
iLenBefore = len(sPagesetsetVisited)
|
| 262 |
+
sPagesetsetVisited.add(sPage)
|
| 263 |
+
iLenAfter = len(sPagesetsetVisited)
|
| 264 |
+
if iLenBefore != iLenAfter:
|
| 265 |
+
with io.open("data/thread_"+str(iId)+"_pages_visited.txt", "a", encoding="utf-8") as f:
|
| 266 |
+
if sPage != "":
|
| 267 |
+
f.write(sPage+"\n")
|
| 268 |
+
|
| 269 |
+
def crawler(iId, iNumberOfThreads, lQueues):
|
| 270 |
+
sPageset = set()
|
| 271 |
+
sPagesetVisited = set()
|
| 272 |
+
readSavedData(iId, sPageset, sPagesetVisited)
|
| 273 |
+
|
| 274 |
+
while True:
|
| 275 |
+
sPage = getNextPage(lQueues, iId, sPageset, sPagesetVisited)
|
| 276 |
+
if sPage is None:
|
| 277 |
+
break
|
| 278 |
+
if "#" in sPage:
|
| 279 |
+
continue
|
| 280 |
+
|
| 281 |
+
if (not "/files/" in sPage) and \
|
| 282 |
+
(not "/video/" in sPage) and \
|
| 283 |
+
(not ".jpg" in sPage) and \
|
| 284 |
+
(not ".pdf" in sPage) and \
|
| 285 |
+
(not ".xml" in sPage) and \
|
| 286 |
+
(not ".pptx" in sPage) and \
|
| 287 |
+
(not ".shtml" in sPage) and \
|
| 288 |
+
len(sPage.split('/')) > 4 and \
|
| 289 |
+
(not ".epub" in sPage):
|
| 290 |
+
|
| 291 |
+
log(iId, sPage)
|
| 292 |
+
for i in range(MAX_RETRIES):
|
| 293 |
+
try:
|
| 294 |
+
lproxies = PROXY_POOL
|
| 295 |
+
proxy = lproxies[int((int(time.time())/1))%len(lproxies)] if lproxies else None
|
| 296 |
+
proxy = lproxies[int(iId)%len(lproxies)] if lproxies else None
|
| 297 |
+
proxies = {'https': proxy, 'http': proxy} if proxy else {}
|
| 298 |
+
browser = mechanicalsoup.StatefulBrowser()
|
| 299 |
+
ua = UserAgent()
|
| 300 |
+
browser.set_user_agent(ua.random)
|
| 301 |
+
browser.session.proxies = proxies
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
browser.open(sPage, timeout=REQUEST_TIMEOUT)
|
| 305 |
+
page = browser.get_current_page()
|
| 306 |
+
page_str = str(page)
|
| 307 |
+
if "#challenge-error-text" in page_str:
|
| 308 |
+
print("error, we will wait a moment and continue")
|
| 309 |
+
time.sleep(1)
|
| 310 |
+
continue
|
| 311 |
+
if "You don't have permission to access" in page_str:
|
| 312 |
+
print("error, we will wait a moment and continue")
|
| 313 |
+
time.sleep(1)
|
| 314 |
+
continue
|
| 315 |
+
raw(iId, sPage, page_str)
|
| 316 |
+
break
|
| 317 |
+
except:
|
| 318 |
+
print(sPage)
|
| 319 |
+
print("retry")
|
| 320 |
+
browser.close()
|
| 321 |
+
continue
|
| 322 |
+
|
| 323 |
+
browser.close()
|
| 324 |
+
else:
|
| 325 |
+
page_str = ""
|
| 326 |
+
|
| 327 |
+
try:
|
| 328 |
+
content = get_content(sPage, page_str)
|
| 329 |
+
except:
|
| 330 |
+
error(iId, sPage)
|
| 331 |
+
|
| 332 |
+
if content['content'] != '':
|
| 333 |
+
file_path = sPage.replace(base_url+"/", "").replace("/", "_")[-200:]
|
| 334 |
+
file_path = "pages/"+file_path
|
| 335 |
+
file_path = file_path[:-1] if file_path.endswith("_") else file_path
|
| 336 |
+
file_path = file_path+".json"
|
| 337 |
+
content_json = json.dumps(content)
|
| 338 |
+
with open(file_path, "w", encoding = "utf-8") as f:
|
| 339 |
+
f.write(content_json)
|
| 340 |
+
else:
|
| 341 |
+
pass
|
| 342 |
+
|
| 343 |
+
sPages = get_urls(page_str)
|
| 344 |
+
addPagesToVisit(sPages, iNumberOfThreads, lQueues)
|
| 345 |
+
addVisitedPages(sPage, sPagesetVisited, iId)
|
| 346 |
+
|
| 347 |
+
print("Thread: " + str(iId) + " chanels visited: " + str(len(sPagesetVisited)) + " channels to visit: " + str(len(sPageset - sPagesetVisited)))
|
| 348 |
+
|
| 349 |
+
def main():
|
| 350 |
+
if not os.path.isdir("pages"):
|
| 351 |
+
os.mkdir("pages")
|
| 352 |
+
|
| 353 |
+
iNumberOfThreads = NUM_THREADS
|
| 354 |
+
lQueues = []
|
| 355 |
+
mgr = multiprocessing.Manager()
|
| 356 |
+
for i in range(iNumberOfThreads):
|
| 357 |
+
qQueue = mgr.Queue()
|
| 358 |
+
lQueues.append(qQueue)
|
| 359 |
+
|
| 360 |
+
lIds = range(0, iNumberOfThreads)
|
| 361 |
+
lNumberOfThreads = [iNumberOfThreads] * iNumberOfThreads
|
| 362 |
+
llQueues = [lQueues] * iNumberOfThreads
|
| 363 |
+
addStartChannel(START_URL, iNumberOfThreads, lQueues)
|
| 364 |
+
lArguments = list(zip(lIds, lNumberOfThreads, llQueues))
|
| 365 |
+
with multiprocessing.Pool(processes=iNumberOfThreads) as pool:
|
| 366 |
+
pool.starmap(crawler, lArguments)
|
| 367 |
+
|
| 368 |
+
if __name__ == "__main__":
|
| 369 |
+
main()
|
scraping/finalize.ipynb
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# `EUobserver (euobserver.com)` — consolidation notebook\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"This notebook is the second half of the pipeline behind\n",
|
| 10 |
+
"[`SinclairSchneider/euobserver_com`](https://huggingface.co/datasets/SinclairSchneider/euobserver_com).\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"`crawler.py` writes one JSON file per article into `pages/`. This notebook\n",
|
| 13 |
+
"\n",
|
| 14 |
+
"1. reads every `pages/*.json`,\n",
|
| 15 |
+
"2. flattens the nested records into one `pandas` column per field,\n",
|
| 16 |
+
"3. drops duplicate articles by headline (`drop_duplicates(subset=['title'])`),\n",
|
| 17 |
+
"4. writes `euobserver_com.json` and pushes the result to the Hugging Face Hub.\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"Outputs have been cleared before publication.\n",
|
| 20 |
+
""
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": null,
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [],
|
| 28 |
+
"source": [
|
| 29 |
+
"import glob\n",
|
| 30 |
+
"import json\n",
|
| 31 |
+
"import pandas as pd\n",
|
| 32 |
+
"from datasets import Dataset\n",
|
| 33 |
+
"import huggingface_hub\n",
|
| 34 |
+
"from dateutil.parser import parse\n",
|
| 35 |
+
"from tqdm import tqdm"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": null,
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"with open(\"pages/*_ar02116e5d.json\", \"r\", encoding=\"utf-8\") as f:\n",
|
| 45 |
+
" json_input = f.read()\n",
|
| 46 |
+
" dict_input_example = json.loads(json_input)"
|
| 47 |
+
]
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"cell_type": "code",
|
| 51 |
+
"execution_count": null,
|
| 52 |
+
"metadata": {},
|
| 53 |
+
"outputs": [],
|
| 54 |
+
"source": [
|
| 55 |
+
"dict_input_example"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": null,
|
| 61 |
+
"metadata": {},
|
| 62 |
+
"outputs": [],
|
| 63 |
+
"source": [
|
| 64 |
+
"json_files = glob.glob(\"pages/*.json\")\n",
|
| 65 |
+
"len(json_files)"
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"cell_type": "code",
|
| 70 |
+
"execution_count": null,
|
| 71 |
+
"metadata": {},
|
| 72 |
+
"outputs": [],
|
| 73 |
+
"source": [
|
| 74 |
+
"title = []\n",
|
| 75 |
+
"content = []\n",
|
| 76 |
+
"author = []\n",
|
| 77 |
+
"description = []\n",
|
| 78 |
+
"keywords = []\n",
|
| 79 |
+
"category = []\n",
|
| 80 |
+
"datePublished = []\n",
|
| 81 |
+
"url = []\n",
|
| 82 |
+
"for file in tqdm(json_files):\n",
|
| 83 |
+
" with open(file, \"r\") as f:\n",
|
| 84 |
+
" d = json.loads(f.read())\n",
|
| 85 |
+
" title.append(d['title'])\n",
|
| 86 |
+
" content.append(d['content'])\n",
|
| 87 |
+
" author.append(d['additional_attributes']['author'])\n",
|
| 88 |
+
" description.append(d['additional_attributes']['description'])\n",
|
| 89 |
+
" keywords.append(d['additional_attributes']['keywords'])\n",
|
| 90 |
+
" category.append(d['additional_attributes']['category'])\n",
|
| 91 |
+
" datePublished.append(d['additional_attributes']['datePublished'])\n",
|
| 92 |
+
" url.append(d['additional_attributes']['url'])"
|
| 93 |
+
]
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"cell_type": "code",
|
| 97 |
+
"execution_count": null,
|
| 98 |
+
"metadata": {},
|
| 99 |
+
"outputs": [],
|
| 100 |
+
"source": [
|
| 101 |
+
"df = pd.DataFrame(\n",
|
| 102 |
+
" {\n",
|
| 103 |
+
" 'title':title,\n",
|
| 104 |
+
" 'content':content,\n",
|
| 105 |
+
" 'author':author,\n",
|
| 106 |
+
" 'description':description,\n",
|
| 107 |
+
" 'keywords':keywords,\n",
|
| 108 |
+
" 'category':category,\n",
|
| 109 |
+
" 'datePublished':datePublished,\n",
|
| 110 |
+
" 'url':url,\n",
|
| 111 |
+
" }\n",
|
| 112 |
+
")"
|
| 113 |
+
]
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"cell_type": "code",
|
| 117 |
+
"execution_count": null,
|
| 118 |
+
"metadata": {},
|
| 119 |
+
"outputs": [],
|
| 120 |
+
"source": [
|
| 121 |
+
"df = df.drop_duplicates(subset=['title'])"
|
| 122 |
+
]
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"cell_type": "code",
|
| 126 |
+
"execution_count": null,
|
| 127 |
+
"metadata": {},
|
| 128 |
+
"outputs": [],
|
| 129 |
+
"source": [
|
| 130 |
+
"df = df[df['datePublished']!=\"\"]"
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"cell_type": "code",
|
| 135 |
+
"execution_count": null,
|
| 136 |
+
"metadata": {},
|
| 137 |
+
"outputs": [],
|
| 138 |
+
"source": [
|
| 139 |
+
"df = df.sort_values(by=['datePublished'], ascending=False).reset_index(drop=True)"
|
| 140 |
+
]
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"cell_type": "code",
|
| 144 |
+
"execution_count": null,
|
| 145 |
+
"metadata": {},
|
| 146 |
+
"outputs": [],
|
| 147 |
+
"source": [
|
| 148 |
+
"df"
|
| 149 |
+
]
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"cell_type": "code",
|
| 153 |
+
"execution_count": null,
|
| 154 |
+
"metadata": {},
|
| 155 |
+
"outputs": [],
|
| 156 |
+
"source": [
|
| 157 |
+
"df.to_json(\"euobserver_com.json\")"
|
| 158 |
+
]
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"cell_type": "code",
|
| 162 |
+
"execution_count": null,
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"outputs": [],
|
| 165 |
+
"source": [
|
| 166 |
+
"ds = Dataset.from_pandas(df)"
|
| 167 |
+
]
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"cell_type": "code",
|
| 171 |
+
"execution_count": null,
|
| 172 |
+
"metadata": {},
|
| 173 |
+
"outputs": [],
|
| 174 |
+
"source": [
|
| 175 |
+
"ds.push_to_hub(\"SinclairSchneider/euobserver_com\")"
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"cell_type": "code",
|
| 180 |
+
"execution_count": null,
|
| 181 |
+
"metadata": {},
|
| 182 |
+
"outputs": [],
|
| 183 |
+
"source": [
|
| 184 |
+
"ds.push_to_hub(\"NLP-UniBW/euobserver_com\")"
|
| 185 |
+
]
|
| 186 |
+
}
|
| 187 |
+
],
|
| 188 |
+
"metadata": {
|
| 189 |
+
"kernelspec": {
|
| 190 |
+
"display_name": "Python 3",
|
| 191 |
+
"language": "python",
|
| 192 |
+
"name": "python3"
|
| 193 |
+
},
|
| 194 |
+
"language_info": {
|
| 195 |
+
"name": "python"
|
| 196 |
+
}
|
| 197 |
+
},
|
| 198 |
+
"nbformat": 4,
|
| 199 |
+
"nbformat_minor": 5
|
| 200 |
+
}
|
scraping/proxies.example.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# One proxy per line. Blank lines and "#" comments are ignored.
|
| 2 |
+
# A scheme is optional - "http://" is assumed when none is given.
|
| 3 |
+
#
|
| 4 |
+
# Copy this file (e.g. to `proxies.txt`), fill in your own entries and point
|
| 5 |
+
# SCRAPER_PROXY_FILE at it:
|
| 6 |
+
#
|
| 7 |
+
# SCRAPER_PROXY_FILE=proxies.txt
|
| 8 |
+
#
|
| 9 |
+
# This is the convenient form for a large proxy farm - the file can hold
|
| 10 |
+
# thousands of lines and be regenerated by another tool at any time.
|
| 11 |
+
|
| 12 |
+
proxy-a.example.com:3128
|
| 13 |
+
proxy-b.example.com:3128
|
| 14 |
+
http://user:pass@proxy-c.example.com:3128
|
| 15 |
+
socks5://localhost:9050
|