Merge branch 'feat-msn-extractor'
commit
46e26c9b85
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,61 @@
|
|||||||
|
// Rename CustomExtractor
|
||||||
|
// to fit your publication
|
||||||
|
// (e.g., NYTimesExtractor)
|
||||||
|
export const MSNExtractor = {
|
||||||
|
domain: 'www.msn.com',
|
||||||
|
title: {
|
||||||
|
selectors: [
|
||||||
|
'h1',
|
||||||
|
// enter title selectors
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
author: {
|
||||||
|
selectors: [
|
||||||
|
'span.authorname-txt',
|
||||||
|
// enter author selectors
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
content: {
|
||||||
|
selectors: [
|
||||||
|
'div.richtext',
|
||||||
|
// enter content selectors
|
||||||
|
],
|
||||||
|
|
||||||
|
// 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: [
|
||||||
|
'span.caption',
|
||||||
|
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
date_published: {
|
||||||
|
selectors: [
|
||||||
|
'span.time',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
lead_image_url: {
|
||||||
|
selectors: [
|
||||||
|
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
dek: {
|
||||||
|
selectors: [
|
||||||
|
['meta[name="description"]', 'value'],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
next_page_url: null,
|
||||||
|
|
||||||
|
excerpt: null,
|
||||||
|
};
|
@ -0,0 +1,134 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
// Rename CustomExtractor
|
||||||
|
describe('MSNExtractor', () => {
|
||||||
|
it('is selected properly', () => {
|
||||||
|
// To pass this test, rename your extractor in
|
||||||
|
// ./src/extractors/custom/www.msn.com/index.js
|
||||||
|
// (e.g., CustomExtractor => NYTimesExtractor)
|
||||||
|
// then add your new extractor to
|
||||||
|
// src/extractors/all.js
|
||||||
|
const url =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
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.msn.com/index.js.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const articleUrl =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
const { title } =
|
||||||
|
await Mercury.parse(articleUrl, html, { fallback: false });
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(title, 'This Is Your Brain On Sad Movies; Plus 5 Films To Cry To');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('returns the author', ((async)) () => {
|
||||||
|
// To pass this test, fill out the author selector
|
||||||
|
// in ./src/extractors/custom/www.msn.com/index.js.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const articleUrl =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
const { author } =
|
||||||
|
await Mercury.parse(articleUrl, html, { fallback: false });
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(author, 'Lizette Borreli');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('returns the date_published', ((async)) () => {
|
||||||
|
// To pass this test, fill out the date_published selector
|
||||||
|
// in ./src/extractors/custom/www.msn.com/index.js.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const articleUrl =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
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-09-21T04:00:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('returns the dek', ((async)) () => {
|
||||||
|
// To pass this test, fill out the dek selector
|
||||||
|
// in ./src/extractors/custom/www.msn.com/index.js.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const articleUrl =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
const { dek } =
|
||||||
|
await Mercury.parse(articleUrl, html, { fallback: false });
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(dek, 'The psychological reason why we love to watch sad movies is linked to the release of endorphins.');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('returns the lead_image_url', ((async)) () => {
|
||||||
|
// To pass this test, fill out the lead_image_url selector
|
||||||
|
// in ./src/extractors/custom/www.msn.com/index.js.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const articleUrl =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
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, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('returns the content', ((async)) () => {
|
||||||
|
// To pass this test, fill out the content selector
|
||||||
|
// in ./src/extractors/custom/www.msn.com/index.js.
|
||||||
|
// You may also want to make use of the clean and transform
|
||||||
|
// options.
|
||||||
|
const html =
|
||||||
|
fs.readFileSync('./fixtures/www.msn.com/1475505231797.html');
|
||||||
|
const url =
|
||||||
|
'http://www.msn.com/en-us/health/wellness/this-is-your-brain-on-sad-movies-plus-5-films-to-cry-to/ar-BBwsPWG?li=BBnb2gg';
|
||||||
|
|
||||||
|
const { content } =
|
||||||
|
await Mercury.parse(url, html, { fallback: false });
|
||||||
|
|
||||||
|
const $ = cheerio.load(content || '');
|
||||||
|
|
||||||
|
const first13 = $('*').first()
|
||||||
|
.text()
|
||||||
|
.trim()
|
||||||
|
.split(/\s+/)
|
||||||
|
.slice(0, 13)
|
||||||
|
.join(' ');
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(first13, 'The psychological reason why we love to watch sad movies is linked to');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue