feat: add netease extractor

feat-netease-extractor
Antoine El Choueiri 2 years ago
parent 112846f74f
commit 7b82640a8f

32
dist/mercury.js vendored

@ -6139,6 +6139,35 @@ var SpektrumExtractor = {
}
};
var 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: []
}
};
var CustomExtractors = /*#__PURE__*/Object.freeze({
@ -6285,7 +6314,8 @@ var CustomExtractors = /*#__PURE__*/Object.freeze({
WwwEngadgetComExtractor: WwwEngadgetComExtractor,
ArstechnicaComExtractor: ArstechnicaComExtractor,
WwwNdtvComExtractor: WwwNdtvComExtractor,
SpektrumExtractor: SpektrumExtractor
SpektrumExtractor: SpektrumExtractor,
Www163ComExtractor: Www163ComExtractor
});
var Extractors = _Object$keys(CustomExtractors).reduce(function (acc, key) {

File diff suppressed because one or more lines are too long

@ -142,3 +142,4 @@ export * from './www.engadget.com';
export * from './arstechnica.com';
export * from './www.ndtv.com';
export * from './www.spektrum.de';
export * from './www.163.com';

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