custom parser for cbc.ca (#699)
Co-authored-by: Andrei Zhemaituk <azhemoytuk@workfusion.com> Co-authored-by: Sarah Doire <sarah.doire@gmail.com> Co-authored-by: Sarah Doire <sarah.doire@postlight.com>pull/700/head^2
parent
6b4359d062
commit
6532316973
File diff suppressed because one or more lines are too long
@ -0,0 +1,36 @@
|
|||||||
|
export const WwwCbcCaExtractor = {
|
||||||
|
domain: 'www.cbc.ca',
|
||||||
|
|
||||||
|
title: {
|
||||||
|
selectors: ['h1'],
|
||||||
|
},
|
||||||
|
|
||||||
|
author: {
|
||||||
|
selectors: ['.authorText', '.bylineDetails'],
|
||||||
|
},
|
||||||
|
|
||||||
|
date_published: {
|
||||||
|
selectors: [['.timeStamp[datetime]', 'datetime']],
|
||||||
|
},
|
||||||
|
|
||||||
|
dek: {
|
||||||
|
selectors: ['.deck'],
|
||||||
|
},
|
||||||
|
|
||||||
|
lead_image_url: {
|
||||||
|
selectors: [['meta[name="og:image"]', 'value']],
|
||||||
|
},
|
||||||
|
|
||||||
|
content: {
|
||||||
|
selectors: ['.story'],
|
||||||
|
|
||||||
|
// 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: [],
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,112 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
import URL from 'url';
|
||||||
|
import cheerio from 'cheerio';
|
||||||
|
|
||||||
|
import Mercury from 'mercury';
|
||||||
|
import getExtractor from 'extractors/get-extractor';
|
||||||
|
import { excerptContent } from 'utils/text';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
describe('WwwCbcCaExtractor', () => {
|
||||||
|
describe('initial test case', () => {
|
||||||
|
let result;
|
||||||
|
let url;
|
||||||
|
beforeAll(() => {
|
||||||
|
url = 'https://www.cbc.ca/news/business/crea-september-numbers-1.6616369';
|
||||||
|
const html = fs.readFileSync('./fixtures/www.cbc.ca/1665765912229.html');
|
||||||
|
result = Mercury.parse(url, { html, fallback: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
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 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.cbc.ca/index.js.
|
||||||
|
const { title } = await result;
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(
|
||||||
|
title,
|
||||||
|
`Housing market slowdown continues with sales and average prices well down from last year`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the author', async () => {
|
||||||
|
// To pass this test, fill out the author selector
|
||||||
|
// in ./src/extractors/custom/www.cbc.ca/index.js.
|
||||||
|
const { author } = await result;
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(author, `Pete Evans`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the date_published', async () => {
|
||||||
|
// To pass this test, fill out the date_published selector
|
||||||
|
// in ./src/extractors/custom/www.cbc.ca/index.js.
|
||||||
|
const { date_published } = await result;
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(date_published, '2022-10-14T16:20:52.800Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the dek', async () => {
|
||||||
|
// To pass this test, fill out the dek selector
|
||||||
|
// in ./src/extractors/custom/www.cbc.ca/index.js.
|
||||||
|
const { dek } = await result;
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(
|
||||||
|
dek,
|
||||||
|
'Average price of a home that sold in September was $640,479'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the lead_image_url', async () => {
|
||||||
|
// To pass this test, fill out the lead_image_url selector
|
||||||
|
// in ./src/extractors/custom/www.cbc.ca/index.js.
|
||||||
|
const { lead_image_url } = await result;
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(
|
||||||
|
lead_image_url,
|
||||||
|
`https://i.cbc.ca/1.6616381.1665753066!/fileImage/httpImage/image.JPG_gen/derivatives/16x9_620/real-estate-sign.JPG`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the content', async () => {
|
||||||
|
// To pass this test, fill out the content selector
|
||||||
|
// in ./src/extractors/custom/www.cbc.ca/index.js.
|
||||||
|
// You may also want to make use of the clean and transform
|
||||||
|
// options.
|
||||||
|
const { content } = await result;
|
||||||
|
|
||||||
|
const $ = cheerio.load(content || '');
|
||||||
|
|
||||||
|
const first13 = excerptContent(
|
||||||
|
$('*')
|
||||||
|
.first()
|
||||||
|
.text(),
|
||||||
|
13
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update these values with the expected values from
|
||||||
|
// the article.
|
||||||
|
assert.equal(
|
||||||
|
first13,
|
||||||
|
'New numbers from the Canadian Real Estate Association confirm what buyers, sellers and'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue