Skip to content

Commit b78c58c

Browse files
janetleekimadampash
authored andcommitted
feat: miami herald parser (#69)
1 parent aedf83e commit b78c58c

4 files changed

Lines changed: 122 additions & 0 deletions

File tree

fixtures/www.miamiherald.com/1481571585318.html

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

src/extractors/custom/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ export * from './www.rollingstone.com';
3636
export * from './247sports.com';
3737
export * from './uproxx.com';
3838
export * from './www.eonline.com';
39+
export * from './www.miamiherald.com';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export const WwwMiamiheraldComExtractor = {
2+
domain: 'www.miamiherald.com',
3+
4+
title: {
5+
selectors: [
6+
'h1.title',
7+
],
8+
},
9+
10+
date_published: {
11+
selectors: [
12+
'p.published-date',
13+
],
14+
15+
timezone: 'America/New_York',
16+
},
17+
18+
lead_image_url: {
19+
selectors: [
20+
['meta[name="og:image"]', 'value'],
21+
],
22+
},
23+
24+
content: {
25+
selectors: [
26+
'div.dateline-storybody',
27+
],
28+
29+
// Is there anything in the content you selected that needs transformed
30+
// before it's consumable content? E.g., unusual lazy loaded images
31+
transforms: {
32+
},
33+
34+
// Is there anything that is in the result that shouldn't be?
35+
// The clean selectors will remove anything that matches from
36+
// the result
37+
clean: [
38+
39+
],
40+
},
41+
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import assert from 'assert';
2+
import fs from 'fs';
3+
import URL from 'url';
4+
import cheerio from 'cheerio';
5+
6+
import Mercury from 'mercury';
7+
import getExtractor from 'extractors/get-extractor';
8+
import { excerptContent } from 'utils/text';
9+
10+
describe('WwwMiamiheraldComExtractor', () => {
11+
describe('initial test case', () => {
12+
let result;
13+
let url;
14+
beforeAll(() => {
15+
url =
16+
'http://www.miamiherald.com/news/business/biz-monday/article120329158.html';
17+
const html =
18+
fs.readFileSync('./fixtures/www.miamiherald.com/1481571585318.html');
19+
result =
20+
Mercury.parse(url, html, { fallback: false });
21+
});
22+
23+
it('is selected properly', () => {
24+
// This test should be passing by default.
25+
// It sanity checks that the correct parser
26+
// is being selected for URLs from this domain
27+
const extractor = getExtractor(url);
28+
assert.equal(extractor.domain, URL.parse(url).hostname);
29+
});
30+
31+
it('returns the title', async () => {
32+
// To pass this test, fill out the title selector
33+
// in ./src/extractors/custom/www.miamiherald.com/index.js.
34+
const { title } = await result;
35+
36+
// Update these values with the expected values from
37+
// the article.
38+
assert.equal(title, 'From Metrorail to bike paths, this is what CEOs think of public transit');
39+
});
40+
41+
it('returns the date_published', async () => {
42+
// To pass this test, fill out the date_published selector
43+
// in ./src/extractors/custom/www.miamiherald.com/index.js.
44+
const { date_published } = await result;
45+
46+
// Update these values with the expected values from
47+
// the article.
48+
assert.equal(date_published, '2016-12-12T12:00:00.000Z');
49+
});
50+
51+
it('returns the lead_image_url', async () => {
52+
// To pass this test, fill out the lead_image_url selector
53+
// in ./src/extractors/custom/www.miamiherald.com/index.js.
54+
const { lead_image_url } = await result;
55+
56+
// Update these values with the expected values from
57+
// the article.
58+
assert.equal(lead_image_url, 'http://www.miamiherald.com/news/local/community/miami-dade/5sz3wg/picture119645963/ALTERNATES/LANDSCAPE_1140/MGB19%20Metrorail%20News%20rk%20(2)');
59+
});
60+
61+
it('returns the content', async () => {
62+
// To pass this test, fill out the content selector
63+
// in ./src/extractors/custom/www.miamiherald.com/index.js.
64+
// You may also want to make use of the clean and transform
65+
// options.
66+
const { content } = await result;
67+
68+
const $ = cheerio.load(content || '');
69+
70+
const first13 = excerptContent($('*').first().text(), 13);
71+
72+
// Update these values with the expected values from
73+
// the article.
74+
assert.equal(first13, 'This week’s question: When is the last time you took public transportation to');
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)