Merge branch 'feat-msn-extractor'

pull/12/head
Toy Vano 8 years ago
commit 46e26c9b85

46
dist/mercury.js vendored

@ -670,6 +670,49 @@ var WiredExtractor = {
excerpt: null
};
// Rename CustomExtractor
// to fit your publication
// (e.g., NYTimesExtractor)
var MSNExtractor = {
domain: 'www.msn.com',
title: {
selectors: ['h1']
},
author: {
selectors: ['span.authorname-txt']
},
content: {
selectors: ['div.richtext'],
// 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
};
var Extractors = {
'nymag.com': NYMagExtractor,
'blogspot.com': BloggerExtractor,
@ -678,7 +721,8 @@ var Extractors = {
'www.nytimes.com': NYTimesExtractor,
'www.theatlantic.com': TheAtlanticExtractor,
'www.newyorker.com': NewYorkerExtractor,
'www.wired.com': WiredExtractor
'www.wired.com': WiredExtractor,
'www.msn.com': MSNExtractor
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -6,6 +6,8 @@ import { NYTimesExtractor } from './custom/www.nytimes.com';
import { TheAtlanticExtractor } from './custom/www.theatlantic.com';
import { NewYorkerExtractor } from './custom/www.newyorker.com';
import { WiredExtractor } from './custom/www.wired.com';
import { MSNExtractor } from './custom/www.msn.com';
const Extractors = {
'nymag.com': NYMagExtractor,
@ -16,6 +18,7 @@ const Extractors = {
'www.theatlantic.com': TheAtlanticExtractor,
'www.newyorker.com': NewYorkerExtractor,
'www.wired.com': WiredExtractor,
'www.msn.com': MSNExtractor,
};

@ -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…
Cancel
Save