-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: aol custom parser * removed work from other commits. merged with latest master
- Loading branch information
1 parent
4cc3b68
commit b415d1d
Showing
5 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export const WwwAolComExtractor = { | ||
domain: 'www.aol.com', | ||
|
||
title: { | ||
selectors: [ | ||
'h1.p-article__title', | ||
], | ||
}, | ||
|
||
author: { | ||
selectors: [ | ||
['meta[name="author"]', 'value'], | ||
], | ||
}, | ||
|
||
date_published: { | ||
selectors: [ | ||
'.p-article__byline__date', | ||
], | ||
|
||
timezone: 'America/New_York', | ||
}, | ||
|
||
dek: { | ||
selectors: [ | ||
// enter selectors | ||
], | ||
}, | ||
|
||
lead_image_url: { | ||
selectors: [ | ||
['meta[name="og:image"]', 'value'], | ||
], | ||
}, | ||
|
||
content: { | ||
selectors: [ | ||
'.article-content', | ||
], | ||
|
||
// Is there anything in the content you selected that needs transformed | ||
// before it's consumable content? E.g., unusual lazy loaded images | ||
transforms: { | ||
}, | ||
|
||
// Is there anything that is in the result that shouldn't be? | ||
// The clean selectors will remove anything that matches from | ||
// the result | ||
clean: [ | ||
|
||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import assert from 'assert'; | ||
import fs from 'fs'; | ||
import URL from 'url'; | ||
import cheerio from 'cheerio'; | ||
|
||
import Mercury from 'mercury'; | ||
import getExtractor from 'extractors/get-extractor'; | ||
import { excerptContent } from 'utils/text'; | ||
|
||
describe('WwwAolComExtractor', () => { | ||
it('is selected properly', () => { | ||
// This test should be passing by default. | ||
// It sanity checks that the correct parser | ||
// is being selected for URLs from this domain | ||
const url = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
const extractor = getExtractor(url); | ||
assert.equal(extractor.domain, URL.parse(url).hostname); | ||
}); | ||
|
||
it('returns the title', async () => { | ||
// To pass this test, fill out the title selector | ||
// in ./src/extractors/custom/www.aol.com/index.js. | ||
const html = | ||
fs.readFileSync('./fixtures/www.aol.com/1480618816916.html'); | ||
const articleUrl = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
|
||
const { title } = | ||
await Mercury.parse(articleUrl, html, { fallback: false }); | ||
|
||
// Update these values with the expected values from | ||
// the article. | ||
assert.equal(title, 'Son of slain police officer given teddy bears made from dad\'s uniform'); | ||
}); | ||
|
||
it('returns the author', async () => { | ||
// To pass this test, fill out the author selector | ||
// in ./src/extractors/custom/www.aol.com/index.js. | ||
const html = | ||
fs.readFileSync('./fixtures/www.aol.com/1480618816916.html'); | ||
const articleUrl = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
|
||
const { author } = | ||
await Mercury.parse(articleUrl, html, { fallback: false }); | ||
|
||
// Update these values with the expected values from | ||
// the article. | ||
assert.equal(author, 'AOL Staff'); | ||
}); | ||
|
||
it('returns the date_published', async () => { | ||
// To pass this test, fill out the date_published selector | ||
// in ./src/extractors/custom/www.aol.com/index.js. | ||
const html = | ||
fs.readFileSync('./fixtures/www.aol.com/1480618816916.html'); | ||
const articleUrl = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
|
||
const { date_published } = | ||
await Mercury.parse(articleUrl, html, { fallback: false }); | ||
|
||
// Update these values with the expected values from | ||
// the article. | ||
assert.equal(date_published, '2016-12-01T18:01:00.000Z'); | ||
}); | ||
|
||
it('returns the lead_image_url', async () => { | ||
// To pass this test, fill out the lead_image_url selector | ||
// in ./src/extractors/custom/www.aol.com/index.js. | ||
const html = | ||
fs.readFileSync('./fixtures/www.aol.com/1480618816916.html'); | ||
const articleUrl = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
|
||
const { lead_image_url } = | ||
await Mercury.parse(articleUrl, html, { fallback: false }); | ||
|
||
// Update these values with the expected values from | ||
// the article. | ||
assert.equal(lead_image_url, 'http://o.aolcdn.com/dims-shared/dims3/GLOB/crop/475x312+0+0/resize/1028x675!/format/jpg/quality/85/http%3A%2F%2Fo.aolcdn.com%2Fhss%2Fstorage%2Fmidas%2Fc8242ab14e089c284b031379d025d64%2F204656928%2FScreen%2BShot%2B2016-12-01%2Bat%2B1.15.51%2BPM.png'); | ||
}); | ||
|
||
it('returns the content', async () => { | ||
// To pass this test, fill out the content selector | ||
// in ./src/extractors/custom/www.aol.com/index.js. | ||
// You may also want to make use of the clean and transform | ||
// options. | ||
const html = | ||
fs.readFileSync('./fixtures/www.aol.com/1480618816916.html'); | ||
const url = | ||
'http://www.aol.com/article/news/2016/12/01/son-of-slain-police-officer-given-teddy-bears-made-from-dads-un/21618553/'; | ||
|
||
const { content } = | ||
await Mercury.parse(url, html, { fallback: false }); | ||
|
||
const $ = cheerio.load(content || ''); | ||
|
||
const first13 = excerptContent($('*').first().text(), 13); | ||
|
||
// Update these values with the expected values from | ||
// the article. | ||
assert.equal(first13, 'ST. LOUIS, MO (KTVI) – Amid unimaginable grief, the widow of slain Saint'); | ||
}); | ||
}); |