Datasets:
Add detailed dataset card and the scraping pipeline used to build it
Browse files- README.md +485 -15
- scraping/.env.example +52 -0
- scraping/README.md +83 -0
- scraping/crawler.py +387 -0
- scraping/finalize.ipynb +196 -0
- scraping/proxies.example.txt +15 -0
README.md
CHANGED
|
@@ -1,4 +1,43 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
dataset_info:
|
| 3 |
features:
|
| 4 |
- name: title
|
|
@@ -21,18 +60,449 @@ dataset_info:
|
|
| 21 |
num_examples: 72119
|
| 22 |
download_size: 189582779
|
| 23 |
dataset_size: 297357295
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- de
|
| 4 |
+
pretty_name: Die Achse des Guten (achgut.com)
|
| 5 |
+
size_categories:
|
| 6 |
+
- 10K<n<100K
|
| 7 |
+
task_categories:
|
| 8 |
+
- text-generation
|
| 9 |
+
- text-classification
|
| 10 |
+
- summarization
|
| 11 |
+
- feature-extraction
|
| 12 |
+
tags:
|
| 13 |
+
- alternative-media
|
| 14 |
+
- blog
|
| 15 |
+
- german
|
| 16 |
+
- journalism
|
| 17 |
+
- media
|
| 18 |
+
- media-bias
|
| 19 |
+
- news
|
| 20 |
+
- news-articles
|
| 21 |
+
- newspaper
|
| 22 |
+
- opinion-journalism
|
| 23 |
+
- politics
|
| 24 |
+
- research-only
|
| 25 |
+
- right-wing
|
| 26 |
+
- text-and-data-mining
|
| 27 |
+
- web-scraping
|
| 28 |
+
annotations_creators:
|
| 29 |
+
- no-annotation
|
| 30 |
+
language_creators:
|
| 31 |
+
- found
|
| 32 |
+
multilinguality:
|
| 33 |
+
- monolingual
|
| 34 |
+
source_datasets:
|
| 35 |
+
- original
|
| 36 |
+
configs:
|
| 37 |
+
- config_name: default
|
| 38 |
+
data_files:
|
| 39 |
+
- split: train
|
| 40 |
+
path: data/train-*
|
| 41 |
dataset_info:
|
| 42 |
features:
|
| 43 |
- name: title
|
|
|
|
| 60 |
num_examples: 72119
|
| 61 |
download_size: 189582779
|
| 62 |
dataset_size: 297357295
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
# Die Achse des Guten (achgut.com)
|
| 66 |
+
|
| 67 |
+
**72 119 German-language news articles** crawled from
|
| 68 |
+
[`www.achgut.com`](https://www.achgut.com/) and published as a Hugging Face dataset.
|
| 69 |
+
This is part of the [German Media collection](https://huggingface.co/collections/SinclairSchneider/german-media),
|
| 70 |
+
a set of comparable corpora covering the German media landscape from public-service
|
| 71 |
+
broadcasters to alternative and fringe outlets, all built with the same crawler and the same
|
| 72 |
+
extraction pipeline so that they can be compared and combined directly.
|
| 73 |
+
|
| 74 |
+
> ## ⚠️ For scientific research only
|
| 75 |
+
>
|
| 76 |
+
> This corpus is published **exclusively for scientific research** under the German
|
| 77 |
+
> research exception for text and data mining — the *Forschungsprivileg* of
|
| 78 |
+
> **§ 60d UrhG** (implementing Art. 3 of EU Directive 2019/790). The article texts remain
|
| 79 |
+
> the copyright of their publisher and are **not** licensed for commercial use,
|
| 80 |
+
> redistribution, or republication. By downloading it you confirm that you use it for
|
| 81 |
+
> non-commercial scientific research. See [Licensing and intended use](#licensing-and-intended-use).
|
| 82 |
+
>
|
| 83 |
+
> The articles are reproduced verbatim from the publisher's website; their content expresses
|
| 84 |
+
> the views of that publisher, not of the dataset author.
|
| 85 |
+
|
| 86 |
+
## At a glance
|
| 87 |
+
|
| 88 |
+
| | |
|
| 89 |
+
|---|---|
|
| 90 |
+
| **Source** | [`www.achgut.com`](https://www.achgut.com/) |
|
| 91 |
+
| **Rows** | 72 119 |
|
| 92 |
+
| **Columns** | 7 (`title`, `content`, `author`, `description`, `category`, `datePublished`, `url`) |
|
| 93 |
+
| **Language** | German (`de`) |
|
| 94 |
+
| **Split** | `train` (single split) |
|
| 95 |
+
| **Format** | Parquet, 1 shard, ≈ 181 MB download / 284 MB in memory |
|
| 96 |
+
| **Perceived partisanship** | 5.2 / 7 → *right of centre* ([medienkompass.org](https://medienkompass.org/deutsche-medienlandschaft/) reader survey) |
|
| 97 |
+
| **Intended use** | Scientific research only (*Forschungsprivileg*, § 60d UrhG) |
|
| 98 |
+
| **Mirror** | [`NLP-UniBW/achgut_de`](https://huggingface.co/datasets/NLP-UniBW/achgut_de) |
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
from datasets import load_dataset
|
| 102 |
+
|
| 103 |
+
ds = load_dataset("SinclairSchneider/achgut_de", split="train")
|
| 104 |
+
print(ds[0]["title"])
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
## About the source
|
| 108 |
+
|
| 109 |
+
[Die Achse des Guten](https://www.achgut.com/) ("Achgut") is a German political group
|
| 110 |
+
blog founded in 2004 by the journalists Henryk M. Broder and Dirk Maxeiner together with Michael Miersch
|
| 111 |
+
and others. It publishes commentary, essays and short "Fundstücke" by a large pool of regular and guest
|
| 112 |
+
authors. The blog describes itself as liberal and pro-Western; it is sharply critical of government
|
| 113 |
+
policy on migration, climate, energy and the Covid-19 pandemic, and media researchers usually place it
|
| 114 |
+
in the conservative-libertarian to right-wing populist spectrum. The output is predominantly opinion
|
| 115 |
+
rather than news reporting, which should be taken into account when the corpus is compared with
|
| 116 |
+
newsroom outlets.
|
| 117 |
+
|
| 118 |
+
## Perceived political position
|
| 119 |
+
|
| 120 |
+
The German media compass at
|
| 121 |
+
[medienkompass.org](https://medienkompass.org/deutsche-medienlandschaft/) places German
|
| 122 |
+
mainstream and alternative outlets on two axes on the basis of a reader survey
|
| 123 |
+
(*n* ≈ 1 154 participants in total, building on a media map by the think tank
|
| 124 |
+
*polisphere*; the quality axis is adapted from Vanessa Otero's media chart).
|
| 125 |
+
|
| 126 |
+
* **x axis — *Parteilichkeit* (partisanship), 1–7:** `< 3.5` left, `3.5 – 4.5` relatively
|
| 127 |
+
neutral, `> 4.5` right.
|
| 128 |
+
`1` far-left (fake news and conspiracy theories) · `2` left mission (questionable journalistic
|
| 129 |
+
standards) · `3` leaning left · `4` minimal partisan tendency · `5` leaning right ·
|
| 130 |
+
`6` right mission (questionable journalistic standards) · `7` far-right (fake news and
|
| 131 |
+
conspiracy theories).
|
| 132 |
+
* **y axis — *Qualität* (quality), 1–5:** `1` sensationalist / clickbait · `2` basic information ·
|
| 133 |
+
`3` meets high standards · `4` analytical · `5` complex.
|
| 134 |
+
|
| 135 |
+
In that survey, **Achgut** is rated:
|
| 136 |
+
|
| 137 |
+
| | Score | Reading |
|
| 138 |
+
|---|---:|---|
|
| 139 |
+
| Partisanship (1–7) | **5.2** | right of centre |
|
| 140 |
+
| Quality (1–5) | **2.4** | on the 1 = clickbait … 5 = complex scale |
|
| 141 |
+
|
| 142 |
+
```
|
| 143 |
+
Parteilichkeit (partisanship): 1 = far left ... 7 = far right
|
| 144 |
+
|
| 145 |
+
1 2 3 4 5 6 7
|
| 146 |
+
|---------|---------|---------|---------|---------|---------|
|
| 147 |
+
^
|
| 148 |
+
Achgut = 5.2
|
| 149 |
+
|
| 150 |
+
left <--------------| neutral |--------------> right
|
| 151 |
+
3.5 4.5
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
For context, here is the full survey table, sorted from left to right — the other outlets in
|
| 155 |
+
the collection are directly comparable:
|
| 156 |
+
|
| 157 |
+
| Outlet | Partisanship (1–7) | Quality (1–5) |
|
| 158 |
+
|---|---:|---:|
|
| 159 |
+
| indymedia | 2.0 | 1.7 |
|
| 160 |
+
| Jungle World | 2.3 | 2.3 |
|
| 161 |
+
| junge Welt | 2.4 | 2.3 |
|
| 162 |
+
| neues Deutschland | 2.6 | 2.3 |
|
| 163 |
+
| der Freitag | 2.7 | 2.9 |
|
| 164 |
+
| die Tageszeitung | 2.8 | 2.7 |
|
| 165 |
+
| Vice | 2.8 | 1.8 |
|
| 166 |
+
| NachDenkSeiten | 3.1 | 3.0 |
|
| 167 |
+
| Frankfurter Rundschau | 3.4 | 2.8 |
|
| 168 |
+
| SPON | 3.5 | 2.1 |
|
| 169 |
+
| Spiegel Print | 3.5 | 2.9 |
|
| 170 |
+
| Süddeutsche | 3.5 | 3.3 |
|
| 171 |
+
| WDR | 3.5 | 2.8 |
|
| 172 |
+
| Tagesspiegel | 3.6 | 2.8 |
|
| 173 |
+
| Zeit | 3.6 | 3.5 |
|
| 174 |
+
| ARD | 3.7 | 2.9 |
|
| 175 |
+
| NDR | 3.7 | 2.8 |
|
| 176 |
+
| Deutschlandfunk | 3.8 | 3.5 |
|
| 177 |
+
| Stern | 3.8 | 2.1 |
|
| 178 |
+
| ZDF | 3.8 | 2.8 |
|
| 179 |
+
| MDR | 4.1 | 2.5 |
|
| 180 |
+
| Handelsblatt | 4.3 | 3.3 |
|
| 181 |
+
| NTV | 4.3 | 2.1 |
|
| 182 |
+
| BR | 4.4 | 2.6 |
|
| 183 |
+
| N24 | 4.4 | 2.0 |
|
| 184 |
+
| Wirtschaftswoche | 4.4 | 3.1 |
|
| 185 |
+
| Frankfurter Allgemeine | 4.5 | 3.3 |
|
| 186 |
+
| RTL | 4.5 | 1.5 |
|
| 187 |
+
| Die Welt | 4.8 | 2.5 |
|
| 188 |
+
| Cicero | 4.9 | 3.1 |
|
| 189 |
+
| Focus Online | 4.9 | 1.7 |
|
| 190 |
+
| Deutsche Wirtschafts Nachrichten | 5.0 | 2.2 |
|
| 191 |
+
| MM News | 5.1 | 1.7 |
|
| 192 |
+
| RT Deutsch | 5.1 | 2.0 |
|
| 193 |
+
| **Achgut** ⬅ this dataset | **5.2** | **2.4** |
|
| 194 |
+
| BILD | 5.2 | 1.3 |
|
| 195 |
+
| Tichys | 5.5 | 2.6 |
|
| 196 |
+
| junge Freiheit | 5.8 | 1.9 |
|
| 197 |
+
| Compact | 6.0 | 1.8 |
|
| 198 |
+
|
| 199 |
+
> **How to read these numbers.** They are *perception* data from a self-selected online survey,
|
| 200 |
+
> not a content analysis: participants rated outlets they know, the sample is not
|
| 201 |
+
> representative of the German population, and the site itself describes the project as an early
|
| 202 |
+
> iteration. Treat them as a rough, crowd-sourced orientation — useful for grouping datasets into
|
| 203 |
+
> coarse political blocks, not as ground truth for bias labelling.
|
| 204 |
+
|
| 205 |
+
## Dataset structure
|
| 206 |
+
|
| 207 |
+
Single `train` split with 72 119 rows and the following columns:
|
| 208 |
+
|
| 209 |
+
| Column | Type | Description | Extracted from |
|
| 210 |
+
|---|---|---|---|
|
| 211 |
+
| `title` | `string` | Headline of the article. | first `<h2>` inside `div#article_maincontent` |
|
| 212 |
+
| `content` | `string` | Full plain-text body of the article. | all `<p>` inside `div#article_maincontent`, space-joined |
|
| 213 |
+
| `author` | `string` | Author(s) as published by the outlet. | text of `div#author_header` |
|
| 214 |
+
| `description` | `string` | Teaser / meta description of the article. | `<meta name="description">` |
|
| 215 |
+
| `category` | `string` | Section the article was published in. | `<meta property="og:type">` |
|
| 216 |
+
| `datePublished` | `string` | Publication timestamp. | the bare text nodes of `div.teaser_text_meta` (the date line under the headline), with tabs, newlines and `/` removed |
|
| 217 |
+
| `url` | `string` | Canonical URL the article was fetched from. | the crawled URL |
|
| 218 |
+
|
| 219 |
+
### Example record
|
| 220 |
+
|
| 221 |
+
```json
|
| 222 |
+
{
|
| 223 |
+
"title": "Beugt Trump das Recht gegen unliebsame Ausländer?",
|
| 224 |
+
"content": "Präsident Donald Trump versucht Schnellabschiebungen mit einem Gesetz aus einem „Sicherheitspaket“ von 1798. Das für die Abschiebungen passende Gesetz wurde aber schon 1800 gestrichen. Hat er solche Mittel nötig? Am 4. März 1801 geschah in Washington, D.C. etwas in der Welt fast Unerhörtes: Ein friedlicher, planvoller und geordneter Regierungswechsel in einem großen Staat aufgrund einer Wahl durch …",
|
| 225 |
+
"author": "Oliver M. Haynold",
|
| 226 |
+
"description": "Präsident Donald Trump versucht Schnellabschiebungen mit einem Gesetz aus einem „Sicherheitspaket“ von 1798. Das für die Abschiebungen passende Gesetz dieses Pakets wurde aber schon 1800 gestrichen. Hat er solche Mittel nötig?",
|
| 227 |
+
"category": "article",
|
| 228 |
+
"datePublished": "27.03.2025 12:00",
|
| 229 |
+
"url": "https://www.achgut.com/artikel/beugt_Trump_das_recht_gegen_unliebsame_Auslaender"
|
| 230 |
+
}
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
## Temporal coverage
|
| 234 |
+
|
| 235 |
+
The `datePublished` column could be parsed for **72 118 of 72 119** rows (100.0 %). Those rows span **2006-10-07 → 2025-06-12**.
|
| 236 |
+
|
| 237 |
+
| Year | Articles | |
|
| 238 |
+
|---:|---:|:---|
|
| 239 |
+
| 2006 | 368 | `██` |
|
| 240 |
+
| 2007 | 3 953 | `█████████████████` |
|
| 241 |
+
| 2008 | 4 577 | `████████████████████` |
|
| 242 |
+
| 2009 | 4 764 | `█████████████████████` |
|
| 243 |
+
| 2010 | 4 557 | `████████████████████` |
|
| 244 |
+
| 2011 | 4 559 | `████████████████████` |
|
| 245 |
+
| 2012 | 3 859 | `█████████████████` |
|
| 246 |
+
| 2013 | 3 865 | `█████████████████` |
|
| 247 |
+
| 2014 | 2 891 | `█████████████` |
|
| 248 |
+
| 2015 | 2 684 | `████████████` |
|
| 249 |
+
| 2016 | 2 988 | `█████████████` |
|
| 250 |
+
| 2017 | 2 939 | `█���███████████` |
|
| 251 |
+
| 2018 | 3 075 | `█████████████` |
|
| 252 |
+
| 2019 | 3 983 | `█████████████████` |
|
| 253 |
+
| 2020 | 4 142 | `██████████████████` |
|
| 254 |
+
| 2021 | 5 483 | `████████████████████████` |
|
| 255 |
+
| 2022 | 3 414 | `███████████████` |
|
| 256 |
+
| 2023 | 3 487 | `███████████████` |
|
| 257 |
+
| 2024 | 4 600 | `████████████████████` |
|
| 258 |
+
| 2025 | 1 930 | `████████` |
|
| 259 |
+
|
| 260 |
+
## How the data was collected
|
| 261 |
+
|
| 262 |
+
The whole pipeline is contained in this repository under [`scraping/`](./scraping) and consists
|
| 263 |
+
of two steps: a distributed crawler that walks the site and writes one JSON file per article, and
|
| 264 |
+
a consolidation notebook that merges those files into the dataset you are reading.
|
| 265 |
+
|
| 266 |
+
### 1. Crawling — [`scraping/crawler.py`](./scraping/crawler.py)
|
| 267 |
+
|
| 268 |
+
The crawler is a breadth-first whole-site crawler built on
|
| 269 |
+
[MechanicalSoup](https://mechanicalsoup.readthedocs.io/) and `multiprocessing`:
|
| 270 |
+
|
| 271 |
+
1. **Sharded frontier.** 32 worker processes each own one `multiprocessing.Manager().Queue()`.
|
| 272 |
+
A URL is assigned to a worker by `int(md5(url).hexdigest(), 16) % 32`, so every URL is always
|
| 273 |
+
handled by the same worker and no locking or cross-process deduplication is needed.
|
| 274 |
+
2. **Seed.** The crawl is seeded with nine URLs: two article pages, the weekly overview
|
| 275 |
+
`https://www.achgut.com/woche` and its pages `P10` … `P50`, and a search page of the article archive
|
| 276 |
+
(that last one contains `#` and is therefore skipped by the URL filter of the published revision).
|
| 277 |
+
Only the first seed (`https://www.achgut.com/artikel/ukraine_krieg_weder_wendepunkt_noch_waffenstillstand`)
|
| 278 |
+
is configurable through `SCRAPER_START_URL`; the others are hard-coded in `main()`.
|
| 279 |
+
3. **Link discovery.** Every fetched page is parsed with BeautifulSoup/lxml; all `<a href>` values
|
| 280 |
+
that start with `https://www.achgut.com/` or with `/` (which are then made absolute) are added to the
|
| 281 |
+
frontier. URLs containing `#` are dropped. In the published revision `get_urls()` itself keeps `#` links; they are removed by
|
| 282 |
+
the URL filter in the next step instead.
|
| 283 |
+
4. **URL filtering.** Before fetching, a URL is skipped when it contains `/files/`, `/video/`, `.jpg`, `.pdf`, `#`, `app-eu.readspeaker.com` or `.epub`.
|
| 284 |
+
5. **Fetching.** Each URL gets up to 1000 attempts with a 10 s timeout.
|
| 285 |
+
6. **Extraction.** `get_content()` turns the HTML into a record (see below). Only pages with a
|
| 286 |
+
non-empty `content` are written out, as `pages/<flattened-url>.json`.
|
| 287 |
+
7. **Resumability.** Each worker appends every known and every visited URL to
|
| 288 |
+
`data/thread_<id>_pages.txt` and `data/thread_<id>_pages_visited.txt`, and re-reads them on
|
| 289 |
+
start, so an interrupted crawl continues where it stopped. Creating a file named `killall.txt`
|
| 290 |
+
in the working directory stops all workers cleanly.
|
| 291 |
+
|
| 292 |
+
Crawler settings used for this site:
|
| 293 |
+
|
| 294 |
+
- **Worker processes:** 32 (`iNumberOfThreads = 32`)
|
| 295 |
+
- **Retries per URL:** 1000, with a 10-second socket timeout per attempt
|
| 296 |
+
- **Proxy pool:** used — a single forward proxy on a private network (selected through `lproxies[int(time.time()/10) % len(lproxies)]`, which would rotate every 10 seconds over a larger pool); the published script applies the same expression to the pool given in `SCRAPER_PROXIES`
|
| 297 |
+
- **User-agent rotation:** yes, a random UA per request via `fake_useragent`, sent together with a fixed set of browser-like `Accept` / `Sec-Fetch-*` headers
|
| 298 |
+
- **Politeness delay:** `time.sleep(random.uniform(1.0, 3.5))` before every request
|
| 299 |
+
- **Bot-challenge handling:** responses containing the site's error page (`Fehlernummer: 1047`) are retried after 1 s, responses containing `You don't have permission to access this resource.` after 10 s
|
| 300 |
+
- **Raw HTML dump:** enabled (`raw/`), used for debugging the parser
|
| 301 |
+
- **Site-specific:** no minimum path depth filter
|
| 302 |
+
|
| 303 |
+
**Paywall handling.** The crawler applies no paywall filter — every fetched page with a non-empty article body was kept.
|
| 304 |
+
|
| 305 |
+
### 2. Article extraction
|
| 306 |
+
|
| 307 |
+
`get_content()` reads the fields from the page's JSON-LD (`<script type="application/ld+json">`)
|
| 308 |
+
and/or its HTML, as follows:
|
| 309 |
+
|
| 310 |
+
| Field | Source in the page |
|
| 311 |
+
|---|---|
|
| 312 |
+
| `title` | first `<h2>` inside `div#article_maincontent` |
|
| 313 |
+
| `content` | all `<p>` inside `div#article_maincontent`, space-joined |
|
| 314 |
+
| `author` | text of `div#author_header` |
|
| 315 |
+
| `description` | `<meta name="description">` |
|
| 316 |
+
| `keywords` | `<meta name="keywords">`, split on `,` — extracted by the crawler but **not** carried into the dataset |
|
| 317 |
+
| `category` | `<meta property="og:type">` |
|
| 318 |
+
| `datePublished` | the bare text nodes of `div.teaser_text_meta` (the date line under the headline), with tabs, newlines and `/` removed |
|
| 319 |
+
| `url` | the crawled URL |
|
| 320 |
+
|
| 321 |
+
The site exposes no usable JSON-LD, so every field is read from the rendered HTML.
|
| 322 |
+
`datePublished` is the German date string shown on the page (`dd.mm.yyyy HH:MM`), not ISO-8601 — parse
|
| 323 |
+
it with `dayfirst=True`.
|
| 324 |
+
|
| 325 |
+
Each article is stored as a JSON file of the shape
|
| 326 |
+
|
| 327 |
+
```json
|
| 328 |
+
{
|
| 329 |
+
"title": "…",
|
| 330 |
+
"content": "…",
|
| 331 |
+
"additional_attributes": { "author": "…", "description": "…", "keywords": "…", "category": "…", "datePublished": "…", "url": "…" }
|
| 332 |
+
}
|
| 333 |
+
```
|
| 334 |
+
|
| 335 |
+
### 3. Consolidation — [`scraping/finalize.ipynb`](./scraping/finalize.ipynb)
|
| 336 |
+
|
| 337 |
+
1. `glob("pages/*.json")` collects every article file.
|
| 338 |
+
2. The nested records are flattened into one `pandas.DataFrame` column per field.
|
| 339 |
+
3. `df.drop_duplicates(subset=['title'])` removes duplicates — the same article is often reachable
|
| 340 |
+
under several URLs (print/mobile variants, tracking parameters, section mirrors), and the
|
| 341 |
+
headline is the most reliable identity key available.
|
| 342 |
+
4. The frame is written to `achgut_de.json` and pushed with
|
| 343 |
+
`datasets.Dataset.from_pandas(df).push_to_hub("SinclairSchneider/achgut_de")`.
|
| 344 |
+
|
| 345 |
+
### Dataset-specific notes
|
| 346 |
+
|
| 347 |
+
- `category` is the page's Open Graph type (`og:type`), not an editorial section, and is `article` for every row — it carries no information.
|
| 348 |
+
- `keywords` was extracted by the crawler but dropped by `finalize.ipynb`, so the dataset has no keyword column.
|
| 349 |
+
- **Two crawler revisions.** The crawl folder holds two revisions of the script. The earlier one (not published) sent all requests through a local Tor SOCKS proxy and paused while a helper script requested a new Tor circuit once a minute; it did not filter URLs containing `#`. The published `crawler.py` is the later revision `achgut_com_2.py`. The dataset contains pages fetched by both: 13 732 rows (19 %) have a `url` with a fragment (e.g. `…/P7#com`, a comment page), which only the earlier revision fetched. Dedup by headline keeps one row per article either way, but the `url` of such a row may point to a comment page rather than to the article's canonical address.
|
| 350 |
+
- The published revision still imports `fp.fp.FreeProxy` and fetches one free proxy at start-up (hence the `free-proxy` dependency). That value is overwritten before every request by the proxy configured through `SCRAPER_PROXIES` (or a direct connection), so it is never actually used; the line is kept so that the script stays exactly as it was run.
|
| 351 |
+
- `description` contains HTML entities such as ` ` taken verbatim from the meta tag.
|
| 352 |
+
|
| 353 |
+
### Reproducing the crawl
|
| 354 |
+
|
| 355 |
+
```bash
|
| 356 |
+
pip install mechanicalsoup beautifulsoup4 lxml python-dateutil fake-useragent free-proxy \
|
| 357 |
+
pandas datasets huggingface_hub tqdm
|
| 358 |
+
|
| 359 |
+
mkdir achgut_de && cd achgut_de
|
| 360 |
+
curl -L -O https://huggingface.co/datasets/SinclairSchneider/achgut_de/resolve/main/scraping/crawler.py
|
| 361 |
+
|
| 362 |
+
python crawler.py # writes pages/*.json; `touch killall.txt` to stop
|
| 363 |
+
jupyter notebook finalize.ipynb
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
#### Routing the crawl through your own proxies
|
| 367 |
+
|
| 368 |
+
The original crawl ran behind a pool of forward proxies on a private network. Those addresses are
|
| 369 |
+
infrastructure-specific and have been **removed** from the published script. Instead, `crawler.py`
|
| 370 |
+
reads the `SCRAPER_PROXIES` environment variable: a comma-separated list of proxies, written with
|
| 371 |
+
or without a scheme (`http://` is assumed when none is given). One entry is picked per request, so
|
| 372 |
+
a pool spreads the load across several exits.
|
| 373 |
+
|
| 374 |
+
```bash
|
| 375 |
+
# a single proxy
|
| 376 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128"
|
| 377 |
+
|
| 378 |
+
# a pool, rotated per request
|
| 379 |
+
export SCRAPER_PROXIES="proxy-a.example.com:3128,proxy-b.example.com:3128"
|
| 380 |
+
|
| 381 |
+
# with an explicit scheme and credentials
|
| 382 |
+
export SCRAPER_PROXIES="http://user:pass@proxy.example.com:3128"
|
| 383 |
+
|
| 384 |
+
# SOCKS, if PySocks is installed
|
| 385 |
+
export SCRAPER_PROXIES="socks5://localhost:9050"
|
| 386 |
+
|
| 387 |
+
# back to a direct connection — this is the default
|
| 388 |
+
unset SCRAPER_PROXIES
|
| 389 |
+
|
| 390 |
+
python crawler.py
|
| 391 |
+
```
|
| 392 |
+
|
| 393 |
+
Internally this becomes `requests`' standard `{'http': …, 'https': …}` proxy mapping; with the
|
| 394 |
+
variable unset the mapping is empty and the crawler connects directly. No credentials, cookies or
|
| 395 |
+
personal data are contained in the published code.
|
| 396 |
+
|
| 397 |
+
**Please crawl responsibly:** respect `robots.txt` and the site's terms of use, keep the
|
| 398 |
+
concurrency far below the 32 workers used here unless you have the site's permission, and prefer
|
| 399 |
+
this published dataset over re-crawling.
|
| 400 |
+
|
| 401 |
+
## Usage
|
| 402 |
+
|
| 403 |
+
```python
|
| 404 |
+
from datasets import load_dataset
|
| 405 |
+
import pandas as pd
|
| 406 |
+
|
| 407 |
+
ds = load_dataset("SinclairSchneider/achgut_de", split="train")
|
| 408 |
+
|
| 409 |
+
# stream instead of downloading everything
|
| 410 |
+
stream = load_dataset("SinclairSchneider/achgut_de", split="train", streaming=True)
|
| 411 |
+
print(next(iter(stream))["title"])
|
| 412 |
+
|
| 413 |
+
# as a DataFrame
|
| 414 |
+
df = ds.to_pandas()
|
| 415 |
+
df["datePublished"] = pd.to_datetime(df["datePublished"], errors="coerce", utc=True, format="mixed", dayfirst=True)
|
| 416 |
+
recent = df[df["datePublished"].dt.year >= 2024]
|
| 417 |
+
print(len(recent), "articles from 2024 onwards")
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
Combining several outlets into one comparative corpus:
|
| 421 |
+
|
| 422 |
+
```python
|
| 423 |
+
from datasets import load_dataset, concatenate_datasets
|
| 424 |
+
|
| 425 |
+
outlets = ["SinclairSchneider/achgut_de", "SinclairSchneider/tagesschau_de"]
|
| 426 |
+
parts = []
|
| 427 |
+
for name in outlets:
|
| 428 |
+
d = load_dataset(name, split="train").select_columns(["title", "content", "url"])
|
| 429 |
+
parts.append(d.add_column("outlet", [name.split("/")[-1]] * len(d)))
|
| 430 |
+
corpus = concatenate_datasets(parts)
|
| 431 |
+
```
|
| 432 |
+
|
| 433 |
+
## Limitations and biases
|
| 434 |
+
|
| 435 |
+
- **Crawl, not archive.** Coverage is whatever was reachable by following links from the seed URL
|
| 436 |
+
at crawl time. Articles that were deleted, depublished or orphaned before the crawl are missing,
|
| 437 |
+
and old content is covered less densely than recent content.
|
| 438 |
+
- **No paywall filter.** No paywall filter was applied: if the site served a truncated teaser instead of a full article, that teaser was kept as it was. Non-article page types (galleries, video pages, live tickers) are mostly absent because they have no extractable body text.
|
| 439 |
+
- **Deduplication by headline.** Two genuinely different articles with an identical headline
|
| 440 |
+
(common for recurring formats such as weather or daily briefings) collapse into one row.
|
| 441 |
+
- **Noisy metadata.** `author`, `category` and `keywords` come straight from the publisher's markup,
|
| 442 |
+
which changed over the years; empty strings are common and category labels are not harmonised
|
| 443 |
+
across outlets.
|
| 444 |
+
- **Editorial perspective.** This is the output of a single outlet. Any model trained on it alone
|
| 445 |
+
inherits that outlet's selection of topics, framing and vocabulary — which is exactly why the
|
| 446 |
+
collection provides the same pipeline across the political spectrum.
|
| 447 |
+
- **No text normalisation.** Bodies are the concatenated paragraphs as published, including
|
| 448 |
+
typographic quotes, soft hyphens and occasional residual boilerplate.
|
| 449 |
+
|
| 450 |
+
## Licensing and intended use
|
| 451 |
+
|
| 452 |
+
### Scientific research only — *Forschungsprivileg* (§ 60d UrhG)
|
| 453 |
+
|
| 454 |
+
This dataset is made available **solely for the purpose of scientific research**. The legal basis
|
| 455 |
+
is the German text-and-data-mining exception for research, the so-called **Forschungsprivileg**:
|
| 456 |
+
|
| 457 |
+
- **§ 60d UrhG** — *Text und Data Mining für Zwecke der wissenschaftlichen Forschung* — allows
|
| 458 |
+
research organisations to make reproductions of lawfully accessible works in order to carry out
|
| 459 |
+
text and data mining for **non-commercial** scientific research, and to share the resulting
|
| 460 |
+
corpus with a specifically limited circle of people for joint research and with individual third
|
| 461 |
+
parties for the purpose of quality assurance.
|
| 462 |
+
- It implements **Art. 3 of Directive (EU) 2019/790** (the DSM Directive); comparable research
|
| 463 |
+
exceptions exist in the other EU member states.
|
| 464 |
+
- § 60d UrhG does **not** cover commercial exploitation. Research organisations that give a
|
| 465 |
+
commercial enterprise preferential access are explicitly excluded from the privilege.
|
| 466 |
+
|
| 467 |
+
### What this means for you
|
| 468 |
+
|
| 469 |
+
✅ **Permitted** — using the corpus for non-commercial scientific research: text and data mining,
|
| 470 |
+
corpus linguistics, media-bias and discourse analysis, training and evaluating research models,
|
| 471 |
+
reproducing published findings, and quality checks by individual third parties.
|
| 472 |
+
|
| 473 |
+
❌ **Not permitted** — commercial use or commercial model training; redistributing or republishing
|
| 474 |
+
the article texts; presenting the texts as your own; building products or services on the article
|
| 475 |
+
texts; any use that substitutes for reading the publisher's own website.
|
| 476 |
+
|
| 477 |
+
The **article texts remain the copyright of Achse des Guten and its publisher.** No licence to them is
|
| 478 |
+
granted or implied by this repository. Only the crawling and extraction code in `scraping/` is
|
| 479 |
+
offered for free reuse.
|
| 480 |
+
|
| 481 |
+
If your intended use falls outside the research exception, obtain permission from the rights
|
| 482 |
+
holder, or use only the derived, non-expressive data (statistics, embeddings, counts). Note that
|
| 483 |
+
§ 60d UrhG also expects research corpora to be deleted once they are no longer needed for the
|
| 484 |
+
research purpose, with archiving permitted at trusted institutions.
|
| 485 |
+
|
| 486 |
+
If you are a rights holder and want content removed, please open a discussion on this repository.
|
| 487 |
+
|
| 488 |
+
> This section is an orientation for researchers, not legal advice. Responsibility for your own
|
| 489 |
+
> use of the data remains with you and your institution.
|
| 490 |
+
|
| 491 |
+
## Citation
|
| 492 |
+
|
| 493 |
+
```bibtex
|
| 494 |
+
@misc{achgut_de_dataset,
|
| 495 |
+
title = {Die Achse des Guten (achgut.com): a corpus of German news articles},
|
| 496 |
+
author = {Schneider, Sinclair},
|
| 497 |
+
year = {2025},
|
| 498 |
+
howpublished = {Hugging Face},
|
| 499 |
+
url = {https://huggingface.co/datasets/SinclairSchneider/achgut_de}
|
| 500 |
+
}
|
| 501 |
+
```
|
| 502 |
+
|
| 503 |
+
## See also
|
| 504 |
+
|
| 505 |
+
- The full [German Media collection](https://huggingface.co/collections/SinclairSchneider/german-media)
|
| 506 |
+
- Mirror of this dataset: [`NLP-UniBW/achgut_de`](https://huggingface.co/datasets/NLP-UniBW/achgut_de)
|
| 507 |
+
- [medienkompass.org — Deutsche Medienlandschaft](https://medienkompass.org/deutsche-medienlandschaft/),
|
| 508 |
+
the source of the perceived-partisanship figures above
|
scraping/.env.example
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ---------------------------------------------------------------------------
|
| 2 |
+
# crawler.py configuration for www.achgut.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=1000
|
| 50 |
+
|
| 51 |
+
# Seed URL the crawl starts from. Any article URL on the site works.
|
| 52 |
+
#SCRAPER_START_URL=https://www.achgut.com/artikel/ukraine_krieg_weder_wendepunkt_noch_waffenstillstand
|
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 `www.achgut.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 free-proxy \
|
| 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,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Whole-site crawler for www.achgut.com (Achse des Guten).
|
| 3 |
+
|
| 4 |
+
This is the exact script that produced the Hugging Face dataset
|
| 5 |
+
https://huggingface.co/datasets/SinclairSchneider/achgut_de — 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://www.achgut.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 free-proxy
|
| 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 |
+
from datetime import datetime
|
| 50 |
+
from fake_useragent import UserAgent
|
| 51 |
+
import random
|
| 52 |
+
|
| 53 |
+
from dateutil.parser import parse
|
| 54 |
+
|
| 55 |
+
from fp.fp import FreeProxy
|
| 56 |
+
|
| 57 |
+
proxy = FreeProxy(country_id=['DE'], rand=True).get()
|
| 58 |
+
proxies = {"http": proxy, "https": proxy}
|
| 59 |
+
|
| 60 |
+
base_url = "https://www.achgut.com/"
|
| 61 |
+
|
| 62 |
+
# --- Configuration ---------------------------------------------------------
|
| 63 |
+
# Every setting below can be supplied through the environment or through a
|
| 64 |
+
# ".env" file placed next to this script. Copy ".env.example" to ".env" and
|
| 65 |
+
# uncomment what you need:
|
| 66 |
+
#
|
| 67 |
+
# cp .env.example .env
|
| 68 |
+
#
|
| 69 |
+
# Nothing has to be set - the defaults are exactly the values that were used
|
| 70 |
+
# for the original crawl.
|
| 71 |
+
def _load_dotenv(path=".env"):
|
| 72 |
+
"""Read a ".env" file: KEY=VALUE per line, "#" starts a comment.
|
| 73 |
+
|
| 74 |
+
Variables that are already set in the real environment win, so a single run
|
| 75 |
+
can still be overridden with e.g. ``SCRAPER_THREADS=4 python crawler.py``.
|
| 76 |
+
"""
|
| 77 |
+
if not os.path.isfile(path):
|
| 78 |
+
return
|
| 79 |
+
with io.open(path, "r", encoding="utf-8") as handle:
|
| 80 |
+
for line in handle:
|
| 81 |
+
line = line.strip()
|
| 82 |
+
if not line or line.startswith("#") or "=" not in line:
|
| 83 |
+
continue
|
| 84 |
+
key, _, value = line.partition("=")
|
| 85 |
+
key = key.strip()
|
| 86 |
+
value = value.strip().strip('"').strip("'")
|
| 87 |
+
if key and key not in os.environ:
|
| 88 |
+
os.environ[key] = value
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
_load_dotenv()
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _load_proxy_pool():
|
| 95 |
+
"""Build the proxy pool from SCRAPER_PROXIES and/or SCRAPER_PROXY_FILE.
|
| 96 |
+
|
| 97 |
+
SCRAPER_PROXIES inline list; entries separated by commas, semicolons,
|
| 98 |
+
spaces or newlines.
|
| 99 |
+
SCRAPER_PROXY_FILE path to a file holding one proxy per line, with blank
|
| 100 |
+
lines and "#" comments allowed. This is the practical
|
| 101 |
+
form for a whole proxy farm: the pool can be swapped or
|
| 102 |
+
regenerated without touching the script or the .env.
|
| 103 |
+
|
| 104 |
+
Both may be combined. Entries may be written with or without a scheme
|
| 105 |
+
("http://" is assumed when none is given). Duplicates are dropped and an
|
| 106 |
+
empty pool simply means "connect directly".
|
| 107 |
+
"""
|
| 108 |
+
raw = os.environ.get("SCRAPER_PROXIES", "")
|
| 109 |
+
proxy_file = os.environ.get("SCRAPER_PROXY_FILE", "").strip()
|
| 110 |
+
if proxy_file:
|
| 111 |
+
if not os.path.isfile(proxy_file):
|
| 112 |
+
raise SystemExit("SCRAPER_PROXY_FILE points to a missing file: " + proxy_file)
|
| 113 |
+
with io.open(proxy_file, "r", encoding="utf-8") as handle:
|
| 114 |
+
raw = raw + "\n" + handle.read()
|
| 115 |
+
cleaned = []
|
| 116 |
+
for line in raw.splitlines():
|
| 117 |
+
line = line.split("#", 1)[0].strip()
|
| 118 |
+
if line:
|
| 119 |
+
cleaned.append(line)
|
| 120 |
+
pool = []
|
| 121 |
+
for entry in re.split(r"[,;\s]+", " ".join(cleaned)):
|
| 122 |
+
entry = entry.strip()
|
| 123 |
+
if not entry:
|
| 124 |
+
continue
|
| 125 |
+
if "://" not in entry:
|
| 126 |
+
entry = "http://" + entry
|
| 127 |
+
if entry not in pool:
|
| 128 |
+
pool.append(entry)
|
| 129 |
+
return pool
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
PROXY_POOL = _load_proxy_pool()
|
| 133 |
+
NUM_THREADS = int(os.environ.get("SCRAPER_THREADS", "32"))
|
| 134 |
+
REQUEST_TIMEOUT = float(os.environ.get("SCRAPER_TIMEOUT", "10.0"))
|
| 135 |
+
MAX_RETRIES = int(os.environ.get("SCRAPER_RETRIES", "1000"))
|
| 136 |
+
START_URL = os.environ.get("SCRAPER_START_URL", "https://www.achgut.com/artikel/ukraine_krieg_weder_wendepunkt_noch_waffenstillstand")
|
| 137 |
+
|
| 138 |
+
def log(number, url):
|
| 139 |
+
if not os.path.isdir("log"):
|
| 140 |
+
os.mkdir("log")
|
| 141 |
+
with open("log"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 142 |
+
f.write(url)
|
| 143 |
+
|
| 144 |
+
def error(number, url):
|
| 145 |
+
if not os.path.isdir("error"):
|
| 146 |
+
os.mkdir("error")
|
| 147 |
+
with open("error"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 148 |
+
f.write(url)
|
| 149 |
+
|
| 150 |
+
def raw(number, url, page_str):
|
| 151 |
+
if not os.path.isdir("raw"):
|
| 152 |
+
os.mkdir("raw")
|
| 153 |
+
with open("raw"+os.sep+"thread_"+str(number)+".txt", "w") as f:
|
| 154 |
+
f.write(url)
|
| 155 |
+
f.write(page_str)
|
| 156 |
+
|
| 157 |
+
def get_content(url, page_str):
|
| 158 |
+
additional_attributes = {
|
| 159 |
+
'author':'',
|
| 160 |
+
'description':'',
|
| 161 |
+
'keywords':'',
|
| 162 |
+
'category':'',
|
| 163 |
+
'datePublished':'',
|
| 164 |
+
'url':'',
|
| 165 |
+
}
|
| 166 |
+
dict_return = {'content':'', 'title':'', 'additional_attributes': additional_attributes}
|
| 167 |
+
if page_str == "":
|
| 168 |
+
return dict_return
|
| 169 |
+
|
| 170 |
+
page_bs = BeautifulSoup(page_str, "lxml")
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
title = page_bs.find("div", {'id':'article_maincontent'}).find("h2").text if page_bs.find("div", {'id':'article_maincontent'}) != None else ""
|
| 174 |
+
content = " ".join([x.text for x in page_bs.find("div", {'id':'article_maincontent'}).find_all("p")]) if page_bs.find("div", {'id':'article_maincontent'}) != None else ""
|
| 175 |
+
author = page_bs.find("div", {'id':'author_header'}).text if page_bs.find("div", {'id':'author_header'}) != None else ""
|
| 176 |
+
description = page_bs.find("meta", {'name':'description'}).get('content', '') if page_bs.find("meta", {'name':'description'}) != None else ""
|
| 177 |
+
keywords = [x for x in page_bs.find("meta", {'name':'keywords'}).get('content', '').split(",") if x != ''] if page_bs.find("meta", {'name':'keywords'}) != None else []
|
| 178 |
+
category = page_bs.find("meta", {'property':'og:type'}).get('content', '') if page_bs.find("meta", {'property':'og:type'}) != None else ""
|
| 179 |
+
datePublished = "".join([x for x in page_bs.find("div", {'class':'teaser_text_meta'}).contents if x.name == None]).replace("\t","").replace("\n", "").replace("/","").replace(" ", " ").strip() if page_bs.find("div", {'class':'teaser_text_meta'}) != 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 url.startswith(base_url):
|
| 198 |
+
return_urls.add(url)
|
| 199 |
+
if url.startswith("/"):
|
| 200 |
+
url = base_url + url
|
| 201 |
+
return_urls.add(url)
|
| 202 |
+
return return_urls
|
| 203 |
+
|
| 204 |
+
def readSavedData(iId, sPageset, sPagesetVisited):
|
| 205 |
+
if not os.path.isdir("data"):
|
| 206 |
+
os.mkdir("data")
|
| 207 |
+
if os.path.isfile("data/thread_"+str(iId)+"_pages.txt"):
|
| 208 |
+
with io.open("data/thread_"+str(iId)+"_pages.txt", "r", encoding="utf-8") as f:
|
| 209 |
+
for line in f:
|
| 210 |
+
line = line.replace("\n", "")
|
| 211 |
+
if line != "":
|
| 212 |
+
sPageset.add(line)
|
| 213 |
+
|
| 214 |
+
if os.path.isfile("data/thread_"+str(iId)+"_pages_visited.txt"):
|
| 215 |
+
with io.open("data/thread_"+str(iId)+"_pages_visited.txt", "r", encoding="utf-8") as f:
|
| 216 |
+
for line in f:
|
| 217 |
+
line = line.replace("\n", "")
|
| 218 |
+
if line != "":
|
| 219 |
+
sPagesetVisited.add(line)
|
| 220 |
+
|
| 221 |
+
def addStartChannel(sPage, iNumberOfThreads, lQueues):
|
| 222 |
+
iIndex = int(hashlib.md5(sPage.encode("utf")).hexdigest(),16)%iNumberOfThreads
|
| 223 |
+
lQueues[iIndex].put(sPage)
|
| 224 |
+
|
| 225 |
+
def getNextPage(lQueues, iId, sPageset, sPagesetVisited):
|
| 226 |
+
while True:
|
| 227 |
+
if os.path.isfile("killall.txt"):
|
| 228 |
+
return None
|
| 229 |
+
|
| 230 |
+
while not lQueues[iId].empty():
|
| 231 |
+
sPage = lQueues[iId].get()
|
| 232 |
+
iLenBefore = len(sPageset)
|
| 233 |
+
sPageset.add(sPage)
|
| 234 |
+
iLenAfter = len(sPageset)
|
| 235 |
+
if iLenBefore != iLenAfter:
|
| 236 |
+
with io.open("data/thread_"+str(iId)+"_pages.txt", "a", encoding="utf-8") as f:
|
| 237 |
+
if sPage != "" and sPage != "\t":
|
| 238 |
+
f.write(sPage + "\n")
|
| 239 |
+
sPagesetToVisit = sPageset - sPagesetVisited
|
| 240 |
+
|
| 241 |
+
if len(sPagesetToVisit) != 0:
|
| 242 |
+
sPage = list(sPagesetToVisit)[0]
|
| 243 |
+
return sPage
|
| 244 |
+
else:
|
| 245 |
+
print("Thread " + str(iId) + " is waiting")
|
| 246 |
+
time.sleep(3)
|
| 247 |
+
|
| 248 |
+
def addPagesToVisit(sPages, iNumberOfThreads, lQueues):
|
| 249 |
+
for sPage in sPages:
|
| 250 |
+
if sPage != "":
|
| 251 |
+
iIndex = int(hashlib.md5(sPage.encode("utf")).hexdigest(), 16) % iNumberOfThreads
|
| 252 |
+
lQueues[iIndex].put(sPage)
|
| 253 |
+
|
| 254 |
+
def addVisitedPages(sPage, sPagesetsetVisited, iId):
|
| 255 |
+
iLenBefore = len(sPagesetsetVisited)
|
| 256 |
+
sPagesetsetVisited.add(sPage)
|
| 257 |
+
iLenAfter = len(sPagesetsetVisited)
|
| 258 |
+
if iLenBefore != iLenAfter:
|
| 259 |
+
with io.open("data/thread_"+str(iId)+"_pages_visited.txt", "a", encoding="utf-8") as f:
|
| 260 |
+
if sPage != "":
|
| 261 |
+
f.write(sPage+"\n")
|
| 262 |
+
|
| 263 |
+
def crawler(iId, iNumberOfThreads, lQueues):
|
| 264 |
+
sPageset = set()
|
| 265 |
+
sPagesetVisited = set()
|
| 266 |
+
readSavedData(iId, sPageset, sPagesetVisited)
|
| 267 |
+
|
| 268 |
+
while True:
|
| 269 |
+
sPage = getNextPage(lQueues, iId, sPageset, sPagesetVisited)
|
| 270 |
+
if sPage is None:
|
| 271 |
+
break
|
| 272 |
+
|
| 273 |
+
if (not "/files/" in sPage) and \
|
| 274 |
+
(not "/video/" in sPage) and \
|
| 275 |
+
(not ".jpg" in sPage) and \
|
| 276 |
+
(not ".pdf" in sPage) and \
|
| 277 |
+
(not "#" in sPage) and \
|
| 278 |
+
(not "app-eu.readspeaker.com" in sPage) and \
|
| 279 |
+
(not ".epub" in sPage):
|
| 280 |
+
|
| 281 |
+
log(iId, sPage)
|
| 282 |
+
for i in range(MAX_RETRIES):
|
| 283 |
+
try:
|
| 284 |
+
|
| 285 |
+
lproxies = PROXY_POOL
|
| 286 |
+
proxy = lproxies[int(int(time.time()/10))%len(lproxies)] if lproxies else None
|
| 287 |
+
proxies = {'https': proxy, 'http': proxy} if proxy else {}
|
| 288 |
+
|
| 289 |
+
browser = mechanicalsoup.StatefulBrowser()
|
| 290 |
+
browser.session.proxies = proxies
|
| 291 |
+
browser.set_user_agent('Mozilla/5.0')
|
| 292 |
+
headers = {
|
| 293 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 294 |
+
'Accept-Language': 'de-DE,de;q=0.9',
|
| 295 |
+
'Accept-Encoding': 'gzip, deflate, br',
|
| 296 |
+
'Connection': 'keep-alive',
|
| 297 |
+
'Upgrade-Insecure-Requests': '1',
|
| 298 |
+
'Sec-Fetch-Dest': 'document',
|
| 299 |
+
'Sec-Fetch-Mode': 'navigate',
|
| 300 |
+
'Sec-Fetch-Site': 'same-origin',
|
| 301 |
+
'Sec-Fetch-User': '?1',
|
| 302 |
+
'Cache-Control': 'max-age=0'
|
| 303 |
+
}
|
| 304 |
+
browser.session.headers.update(headers)
|
| 305 |
+
|
| 306 |
+
ua = UserAgent()
|
| 307 |
+
browser.set_user_agent(ua.random)
|
| 308 |
+
time.sleep(random.uniform(1.0, 3.5))
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
browser.open(sPage, timeout=REQUEST_TIMEOUT)
|
| 312 |
+
page = browser.get_current_page()
|
| 313 |
+
page_str = str(page)
|
| 314 |
+
raw(iId, sPage, page_str)
|
| 315 |
+
if "Es ist ein Fehler aufgetreten (Fehlernummer: 1047)." in page_str:
|
| 316 |
+
print("error, we will wait a moment and continue")
|
| 317 |
+
time.sleep(1)
|
| 318 |
+
continue
|
| 319 |
+
if "You don't have permission to access this resource." in page_str:
|
| 320 |
+
print("error 403, we will wait a moment and continue")
|
| 321 |
+
time.sleep(10)
|
| 322 |
+
continue
|
| 323 |
+
break
|
| 324 |
+
except Exception as e:
|
| 325 |
+
print(sPage)
|
| 326 |
+
print(f"Error: {str(e)} - Rotating proxy")
|
| 327 |
+
print("retry")
|
| 328 |
+
time.sleep(3)
|
| 329 |
+
|
| 330 |
+
browser.close()
|
| 331 |
+
continue
|
| 332 |
+
|
| 333 |
+
browser.close()
|
| 334 |
+
else:
|
| 335 |
+
page_str = ""
|
| 336 |
+
|
| 337 |
+
try:
|
| 338 |
+
content = get_content(sPage, page_str)
|
| 339 |
+
except:
|
| 340 |
+
error(iId, sPage)
|
| 341 |
+
|
| 342 |
+
if content['content'] != '':
|
| 343 |
+
file_path = sPage.replace(base_url+"/", "").replace("/", "_")[-200:]
|
| 344 |
+
file_path = "pages/"+file_path
|
| 345 |
+
file_path = file_path[:-1] if file_path.endswith("_") else file_path
|
| 346 |
+
file_path = file_path+".json"
|
| 347 |
+
content_json = json.dumps(content)
|
| 348 |
+
with open(file_path, "w", encoding = "utf-8") as f:
|
| 349 |
+
f.write(content_json)
|
| 350 |
+
else:
|
| 351 |
+
pass
|
| 352 |
+
|
| 353 |
+
sPages = get_urls(page_str)
|
| 354 |
+
addPagesToVisit(sPages, iNumberOfThreads, lQueues)
|
| 355 |
+
addVisitedPages(sPage, sPagesetVisited, iId)
|
| 356 |
+
|
| 357 |
+
print("Thread: " + str(iId) + " chanels visited: " + str(len(sPagesetVisited)) + " channels to visit: " + str(len(sPageset - sPagesetVisited)))
|
| 358 |
+
|
| 359 |
+
def main():
|
| 360 |
+
if not os.path.isdir("pages"):
|
| 361 |
+
os.mkdir("pages")
|
| 362 |
+
|
| 363 |
+
iNumberOfThreads = NUM_THREADS
|
| 364 |
+
lQueues = []
|
| 365 |
+
mgr = multiprocessing.Manager()
|
| 366 |
+
for i in range(iNumberOfThreads):
|
| 367 |
+
qQueue = mgr.Queue()
|
| 368 |
+
lQueues.append(qQueue)
|
| 369 |
+
|
| 370 |
+
lIds = range(0, iNumberOfThreads)
|
| 371 |
+
lNumberOfThreads = [iNumberOfThreads] * iNumberOfThreads
|
| 372 |
+
llQueues = [lQueues] * iNumberOfThreads
|
| 373 |
+
addStartChannel(START_URL, iNumberOfThreads, lQueues)
|
| 374 |
+
addStartChannel("https://www.achgut.com/artikel/kommt_jetzt_die_musk_partei", iNumberOfThreads, lQueues)
|
| 375 |
+
addStartChannel("https://www.achgut.com/woche", iNumberOfThreads, lQueues)
|
| 376 |
+
addStartChannel("https://www.achgut.com/woche/P10", iNumberOfThreads, lQueues)
|
| 377 |
+
addStartChannel("https://www.achgut.com/woche/P20", iNumberOfThreads, lQueues)
|
| 378 |
+
addStartChannel("https://www.achgut.com/woche/P30", iNumberOfThreads, lQueues)
|
| 379 |
+
addStartChannel("https://www.achgut.com/woche/P40", iNumberOfThreads, lQueues)
|
| 380 |
+
addStartChannel("https://www.achgut.com/woche/P50", iNumberOfThreads, lQueues)
|
| 381 |
+
addSt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mFiZWwgU2NodW5rZXxWb2xrZXIgU2VpdHp8Sm9hY2hpbSBOaWtvbGF1cyBTdGVpbmhcdTAwZjZmZWx8Q29yYSBTdGVwaGFufFJcdTAwZmNkaWdlciBTdG9iYmV8VWxyaWtlIFN0b2NrbWFubnxLYXRoYXJpbmEgU3phYm98VGhpbG8gVGhpZWxrZXxKYW4gVG9tYXNjaG9mZnxBaXIgVHVlcmtpc3xNYXJrdXMgVmFobGVmZWxkfEZyZWQgVmllYmFobnxSaWNoYXJkIFdhZ25lcnxCZW5qYW1pbiBXZWludGhhbHxHdW50ZXIgV2VpXHUwMGRmZ2VyYmVyfEFsZXhhbmRlciBXZW5kdHxKb2NoZW4gWmllZ2xlcnxPbGl2ZXIgWmltc2tpfEtvbGphIFp5ZGF0aXNzIn0#artikelarchiv", iNumberOfThreads, lQueues)
|
| 382 |
+
lArguments = list(zip(lIds, lNumberOfThreads, llQueues))
|
| 383 |
+
with multiprocessing.Pool(processes=iNumberOfThreads) as pool:
|
| 384 |
+
pool.starmap(crawler, lArguments)
|
| 385 |
+
|
| 386 |
+
if __name__ == "__main__":
|
| 387 |
+
main()
|
scraping/finalize.ipynb
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# `Die Achse des Guten (achgut.com)` — consolidation notebook\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"This notebook is the second half of the pipeline behind\n",
|
| 10 |
+
"[`SinclairSchneider/achgut_de`](https://huggingface.co/datasets/SinclairSchneider/achgut_de).\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 `achgut_de.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/https:__www.achgut.com_artikel_zypern_will_nicht.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 |
+
"files = glob.glob(\"pages/*.json\")"
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"cell_type": "code",
|
| 69 |
+
"execution_count": null,
|
| 70 |
+
"metadata": {},
|
| 71 |
+
"outputs": [],
|
| 72 |
+
"source": [
|
| 73 |
+
"title = []\n",
|
| 74 |
+
"content = []\n",
|
| 75 |
+
"author = []\n",
|
| 76 |
+
"description = []\n",
|
| 77 |
+
"category = []\n",
|
| 78 |
+
"datePublished = []\n",
|
| 79 |
+
"url = []\n",
|
| 80 |
+
"for file in tqdm(files):\n",
|
| 81 |
+
" with open(file, \"r\") as f:\n",
|
| 82 |
+
" d = json.loads(f.read())\n",
|
| 83 |
+
" title.append(d['title'])\n",
|
| 84 |
+
" content.append(d['content'])\n",
|
| 85 |
+
" author.append(d['additional_attributes']['author'])\n",
|
| 86 |
+
" description.append(d['additional_attributes']['description'])\n",
|
| 87 |
+
" category.append(d['additional_attributes']['category'])\n",
|
| 88 |
+
" datePublished.append(d['additional_attributes']['datePublished'])\n",
|
| 89 |
+
" url.append(d['additional_attributes']['url'])"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"cell_type": "code",
|
| 94 |
+
"execution_count": null,
|
| 95 |
+
"metadata": {},
|
| 96 |
+
"outputs": [],
|
| 97 |
+
"source": [
|
| 98 |
+
"df = pd.DataFrame(\n",
|
| 99 |
+
" {\n",
|
| 100 |
+
" 'title': title,\n",
|
| 101 |
+
" 'content': content,\n",
|
| 102 |
+
" 'author': author,\n",
|
| 103 |
+
" 'description': description,\n",
|
| 104 |
+
" 'category': category,\n",
|
| 105 |
+
" 'datePublished': datePublished,\n",
|
| 106 |
+
" 'url': url,\n",
|
| 107 |
+
" }\n",
|
| 108 |
+
")"
|
| 109 |
+
]
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"cell_type": "code",
|
| 113 |
+
"execution_count": null,
|
| 114 |
+
"metadata": {},
|
| 115 |
+
"outputs": [],
|
| 116 |
+
"source": [
|
| 117 |
+
"df"
|
| 118 |
+
]
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"cell_type": "code",
|
| 122 |
+
"execution_count": null,
|
| 123 |
+
"metadata": {},
|
| 124 |
+
"outputs": [],
|
| 125 |
+
"source": [
|
| 126 |
+
"df = df.drop_duplicates(subset=['title'])"
|
| 127 |
+
]
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"cell_type": "code",
|
| 131 |
+
"execution_count": null,
|
| 132 |
+
"metadata": {},
|
| 133 |
+
"outputs": [],
|
| 134 |
+
"source": [
|
| 135 |
+
"df = df.reset_index(drop=True)"
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"cell_type": "code",
|
| 140 |
+
"execution_count": null,
|
| 141 |
+
"metadata": {},
|
| 142 |
+
"outputs": [],
|
| 143 |
+
"source": [
|
| 144 |
+
"df"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"cell_type": "code",
|
| 149 |
+
"execution_count": null,
|
| 150 |
+
"metadata": {},
|
| 151 |
+
"outputs": [],
|
| 152 |
+
"source": [
|
| 153 |
+
"df.to_json(\"achgut_de.json\")"
|
| 154 |
+
]
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"cell_type": "code",
|
| 158 |
+
"execution_count": null,
|
| 159 |
+
"metadata": {},
|
| 160 |
+
"outputs": [],
|
| 161 |
+
"source": [
|
| 162 |
+
"ds = Dataset.from_pandas(df)"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "code",
|
| 167 |
+
"execution_count": null,
|
| 168 |
+
"metadata": {},
|
| 169 |
+
"outputs": [],
|
| 170 |
+
"source": [
|
| 171 |
+
"ds.push_to_hub(\"SinclairSchneider/achgut_de\")"
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"cell_type": "code",
|
| 176 |
+
"execution_count": null,
|
| 177 |
+
"metadata": {},
|
| 178 |
+
"outputs": [],
|
| 179 |
+
"source": [
|
| 180 |
+
"ds.push_to_hub(\"NLP-UniBW/achgut_de\")"
|
| 181 |
+
]
|
| 182 |
+
}
|
| 183 |
+
],
|
| 184 |
+
"metadata": {
|
| 185 |
+
"kernelspec": {
|
| 186 |
+
"display_name": "Python 3",
|
| 187 |
+
"language": "python",
|
| 188 |
+
"name": "python3"
|
| 189 |
+
},
|
| 190 |
+
"language_info": {
|
| 191 |
+
"name": "python"
|
| 192 |
+
}
|
| 193 |
+
},
|
| 194 |
+
"nbformat": 4,
|
| 195 |
+
"nbformat_minor": 5
|
| 196 |
+
}
|
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
|