Skip to content

Commit f95947f

Browse files
svenwiegandmtashley
authored andcommitted
Implemented custom extractor epaper.zeit.de (#488)
1 parent 2422e47 commit f95947f

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="de">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" value="IE=edge">
6+
<meta name="viewport" value="width=device-width, initial-scale=1">
7+
<meta name="robots" value="noindex, nofollow, noarchive">
8+
<title>Was hei&#xDF;t Sozialismus f&#xFC;r Sie, Kevin K&#xFC;hnert?</title>
9+
<link rel="stylesheet" href="https://epaper.zeit.de/css/article/bootstrap.min.css"> <link rel="stylesheet" href="https://epaper.zeit.de/css/article/article.css"></head>
10+
<body class="hyphenate">
11+
<div class="container">
12+
<div class="row">
13+
<div class="col-xs-12">
14+
15+
<div class="article">
16+
<div class="article__author">
17+
Politik &#xB7; Jochen Bittner, Tina Hildebrandt </div>
18+
<div class="article__content" id="articleContent">
19+
<p class="title">Was hei&#xDF;t Sozialismus f&#xFC;r Sie, Kevin K&#xFC;hnert?</p> <subtitle>Zum Beispiel die Kollektivierung von Firmen wie BMW, sagt der Chef der Jusos. In der Wirtschaftsordnung, die er sich vorstellt, g&#xE4;be es auch kein Eigentum an Wohnraum mehr. Ein Gespr&#xE4;ch &#xFC;ber eine radikale Alternative</subtitle> <image-credits>Foto: Tibor Boz/Redux/laif</image-credits> <box type="citation">
20+
<p>&#xBB;Der Zeitgeist ist nun wirklich kein altruistischer&#xAB;</p>
21+
<author>xxx</author>
22+
</box> <division author="DIE ZEIT" type="interview"> <p>DIE ZEIT: Herr K&#xFC;hnert, Sie nennen sich einen Sozialisten. Was verstehen Sie darunter?</p> </division> <division author="Kevin K&#xFC;hnert" type="interview"> <p>Kevin K&#xFC;hnert: Das ist erst mal ein Nichteinverst&#xE4;ndnis mit der Wirtschafts- und teilweise auch mit der Gesellschaftsordnung. Es markiert den Anspruch, dass eine bessere Welt nicht nur denkbar, sondern auch realisierbar ist. Sprich: eine Welt freier Menschen, die kollektive Bed&#xFC;rfnisse in den Vordergrund stellt und nicht Profitstreben.</p> </division> <division author="ZEIT" type="interview"> <p>ZEIT: Das klingt etwas blumig. Die klassische Definition hei&#xDF;t: Vergesellschaftung von Produktionsmitteln. Unterschreiben Sie das?</p> </division> <division author="K&#xFC;hnert" type="interview"> <p>K&#xFC;hnert: Wenn wir Sozialismus sagen, haben wir oft Bilder aus der Marxschen Zeit vor uns: gro&#xDF;e Fabriken, die nicht denen geh&#xF6;ren, die darin arbeiten. In unsere heutige Zeit &#xFC;bersetzt, reden wir &#xFC;ber den Umgang mit Internetgiganten, den Zugang zu gro&#xDF;en Datenmengen und ob das wirklich in privatwirtschaftlicher Hand sein sollte. Der Grundsatz ist unver&#xE4;ndert: Was unser Leben bestimmt, soll in der Hand der Gesellschaft sein und demokratisch von ihr bestimmt werden. Eine Welt, in der Menschen ihren Bed&#xFC;rfnissen nachgehen k&#xF6;nnen. Eine Demokratisierung aller Lebensbereiche.</p> </division> <byline>DIE FRAGEN STELLTEN JOCHEN BITTNER UND TINA HILDEBRANDT </byline> <linkbox> <text>Lesen Sie eine l&#xE4;ngere Version des Interviews bei ZEIT ONLINE unter </text> <link>www.zeit.de/kevin-kuehnert </linkbox> <p class="caption">Mieten oder kaufen? F&#xFC;r Kevin K&#xFC;hnert eine Frage des Gemeinwohls</p> </div>
23+
</div>
24+
25+
26+
27+
</div>
28+
</div>
29+
</div>
30+
</body>
31+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const EpaperZeitDeExtractor = {
2+
domain: 'epaper.zeit.de',
3+
4+
title: {
5+
selectors: ['p.title'],
6+
},
7+
8+
author: {
9+
selectors: ['.article__author'],
10+
},
11+
12+
date_published: null,
13+
14+
excerpt: {
15+
selectors: ['subtitle'],
16+
},
17+
18+
lead_image_url: null,
19+
20+
content: {
21+
selectors: ['.article'],
22+
23+
// Is there anything in the content you selected that needs transformed
24+
// before it's consumable content? E.g., unusual lazy loaded images
25+
transforms: {
26+
'p.title': 'h1',
27+
'.article__author': 'p',
28+
byline: 'p',
29+
linkbox: 'p',
30+
},
31+
32+
// Is there anything that is in the result that shouldn't be?
33+
// The clean selectors will remove anything that matches from
34+
// the result
35+
clean: ['image-credits', 'box[type=citation]'],
36+
},
37+
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import assert from 'assert';
2+
import URL from 'url';
3+
import cheerio from 'cheerio';
4+
5+
import Mercury from 'mercury';
6+
import getExtractor from 'extractors/get-extractor';
7+
import { excerptContent } from 'utils/text';
8+
9+
const fs = require('fs');
10+
11+
describe('EpaperZeitDeExtractor', () => {
12+
describe('initial test case', () => {
13+
let result;
14+
let url;
15+
beforeAll(() => {
16+
url =
17+
'https://epaper.zeit.de/article/702225a4061dfbf97ab93df8de77e8c54aa3f5fe7a8c2799e8d425953d123acf';
18+
const html = fs.readFileSync(
19+
'./fixtures/epaper.zeit.de/1566927390034.html'
20+
);
21+
result = Mercury.parse(url, { html, fallback: false });
22+
});
23+
24+
it('is selected properly', () => {
25+
// This test should be passing by default.
26+
// It sanity checks that the correct parser
27+
// is being selected for URLs from this domain
28+
const extractor = getExtractor(url);
29+
assert.equal(extractor.domain, URL.parse(url).hostname);
30+
});
31+
32+
it('returns the title', async () => {
33+
// To pass this test, fill out the title selector
34+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
35+
const { title } = await result;
36+
37+
// Update these values with the expected values from
38+
// the article.
39+
assert.equal(title, `Was heißt Sozialismus für Sie, Kevin Kühnert?`);
40+
});
41+
42+
it('returns the author', async () => {
43+
// To pass this test, fill out the author selector
44+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
45+
const { author } = await result;
46+
47+
// Update these values with the expected values from
48+
// the article.
49+
assert.equal(author, 'Politik · Jochen Bittner, Tina Hildebrandt');
50+
});
51+
52+
it('returns the date_published', async () => {
53+
// To pass this test, fill out the date_published selector
54+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
55+
const { date_published } = await result;
56+
57+
// Update these values with the expected values from
58+
// the article.
59+
assert.equal(date_published, null);
60+
});
61+
62+
it('returns the excerpt', async () => {
63+
// To pass this test, fill out the excerpt selector
64+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
65+
const { excerpt } = await result;
66+
67+
// Update these values with the expected values from
68+
// the article.
69+
assert.equal(
70+
excerpt,
71+
'Zum Beispiel die Kollektivierung von Firmen wie BMW, sagt der Chef der Jusos. In der Wirtschaftsordnung, die er sich vorstellt, gäbe es auch kein Eigentum an Wohnraum mehr. Ein Gespräch über eine radikale Alternative'
72+
);
73+
});
74+
75+
it('returns the lead_image_url', async () => {
76+
// To pass this test, fill out the lead_image_url selector
77+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
78+
const { lead_image_url } = await result;
79+
80+
// Update these values with the expected values from
81+
// the article.
82+
assert.equal(lead_image_url, null);
83+
});
84+
85+
it('returns the content', async () => {
86+
// To pass this test, fill out the content selector
87+
// in ./src/extractors/custom/epaper.zeit.de/index.js.
88+
// You may also want to make use of the clean and transform
89+
// options.
90+
const { content } = await result;
91+
92+
const $ = cheerio.load(content || '');
93+
94+
const first13 = excerptContent(
95+
$('*')
96+
.first()
97+
.text(),
98+
13
99+
);
100+
101+
// Update these values with the expected values from
102+
// the article.
103+
assert.equal(
104+
first13,
105+
'Politik · Jochen Bittner, Tina Hildebrandt Zum Beispiel die Kollektivierung von Firmen wie'
106+
);
107+
});
108+
});
109+
});

src/extractors/custom/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,4 @@ export * from './www.lemonde.fr';
131131
export * from './www.phoronix.com';
132132
export * from './pitchfork.com';
133133
export * from './biorxiv.org';
134+
export * from './epaper.zeit.de';

0 commit comments

Comments
 (0)