feat: add netease extractor
parent
112846f74f
commit
7b82640a8f
File diff suppressed because one or more lines are too long
@ -0,0 +1,40 @@
|
||||
export const Www163ComExtractor = {
|
||||
domain: 'www.163.com',
|
||||
|
||||
title: {
|
||||
selectors: [['meta[property="og:title"]', 'content'], '.post_title'],
|
||||
},
|
||||
|
||||
author: {
|
||||
selectors: [
|
||||
['meta[name="author"]', 'content'],
|
||||
['meta[property="article:author"]', 'content'],
|
||||
'.post_author',
|
||||
],
|
||||
},
|
||||
|
||||
date_published: {
|
||||
selectors: [['meta[property="article:published_time"]', 'content']],
|
||||
},
|
||||
|
||||
dek: {
|
||||
selectors: [],
|
||||
},
|
||||
|
||||
lead_image_url: {
|
||||
selectors: ['p.f_center img'],
|
||||
},
|
||||
|
||||
content: {
|
||||
selectors: ['.post_body'],
|
||||
|
||||
// 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,65 @@
|
||||
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('Www163ComExtractor', () => {
|
||||
describe('initial test case', () => {
|
||||
let result;
|
||||
let url;
|
||||
beforeAll(() => {
|
||||
url = 'https://www.163.com/dy/article/GA1LTCMN051480KF.html';
|
||||
const html = fs.readFileSync('./fixtures/www.163.com/1660814937204.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.163.com/index.js.
|
||||
const { title } = await result;
|
||||
|
||||
// Update these values with the expected values from
|
||||
// the article.
|
||||
assert.equal(
|
||||
title,
|
||||
`破解难题!西安交大团队开发出高密度固态储氢材料:安全可控,稳定释氢`
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the date_published', async () => {
|
||||
// To pass this test, fill out the date_published selector
|
||||
// in ./src/extractors/custom/www.163.com/index.js.
|
||||
const { date_published } = await result;
|
||||
|
||||
// Update these values with the expected values from
|
||||
// the article.
|
||||
assert.equal(date_published, `2021-05-15T03:36:10.000Z`);
|
||||
});
|
||||
|
||||
it('returns the lead_image_url', async () => {
|
||||
// To pass this test, fill out the lead_image_url selector
|
||||
// in ./src/extractors/custom/www.163.com/index.js.
|
||||
const { lead_image_url } = await result;
|
||||
|
||||
// Update these values with the expected values from
|
||||
// the article.
|
||||
assert.equal(
|
||||
lead_image_url,
|
||||
'https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F0515%2F8b37ab4aj00qt4q08003qc000hs00b2g.jpg&thumbnail=660x2147483647&quality=80&type=jpg'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue