Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ftchinese parser #264

Closed
wants to merge 9 commits into from
Closed

feat: add ftchinese parser #264

wants to merge 9 commits into from

Conversation

HenryQW
Copy link

@HenryQW HenryQW commented Feb 9, 2019

It seems the parser can't handle Chinese characters for content, but works for title, author and dek.

Preview is showing a bunch of unicode rather than the actual Chinese characters.

{
  "title": "欧盟否决西门子-阿尔斯通铁路业务合并案",
  "content": "<div><div id=\"story-body-container\"><p>&#x5FB7;&#x56FD;&#x548C;&#x6CD5;&#x56FD;&#x94C1;&#x8DEF;&#x8BBE;&#x5907;&#x5236;&#x9020;&#x5546;&#x897F;&#x95E8;&#x5B50;(Siemens)&#x4E0E;&#x963F;&#x5C14;&#x65AF;&#x901A;(Alstom)&#x4E4B;&#x95F4;&#x7684;&#x5408;&#x5E76;&#x5DF2;&#x88AB;&#x6B27;&#x76DF;&#x7ADE;&#x4E89;&#x6267;&#x6CD5;&#x673A;&#x6784;&#x5426;&#x51B3;&#xFF0C;&#x76D1;&#x7BA1;&#x8005;&#x4E0D;&#x63A5;&#x53D7;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x89C2;&#x70B9;&#xFF0C;&#x5373;&#x8FD9;&#x4E00;&#x8054;&#x59FB;&#x5BF9;&#x4E8E;&#x6B27;&#x6D32;&#x4E0E;&#x7531;&#x56FD;&#x5BB6;&#x652F;&#x6301;&#x7684;&#x4E2D;&#x56FD;&#x7ADE;&#x4E89;&#x5BF9;&#x624B;&#x7ADE;&#x4E89;&#x662F;&#x5FC5;&#x8981;&#x7684;&#x3002;</p><p>&#x6B27;&#x76DF;&#x7ADE;&#x4E89;&#x4E8B;&#x52A1;&#x4E13;&#x5458;&#x739B;&#x683C;&#x4E3D;&#x7279;&#x2022;&#x7EF4;&#x65AF;&#x7279;&#x683C;(Margrethe Vestager)&#x5468;&#x4E09;&#x5BA3;&#x5E03;&#x4E86;&#x8FD9;&#x9879;&#x5426;&#x51B3;&#x3002;&#x6B64;&#x524D;&#xFF0C;&#x5176;&#x4ED6;&#x6B27;&#x76DF;&#x4E13;&#x5458;&#x4EE5;&#x53CA;&#x5404;&#x56FD;&#x76D1;&#x7BA1;&#x673A;&#x6784;&#x652F;&#x6301;&#x5979;&#x7684;&#x7ACB;&#x573A;&#xFF0C;&#x5373;&#x8FD9;&#x7B14;&#x4EA4;&#x6613;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x4EF7;&#x683C;&#x4E0A;&#x6DA8;&#x5E76;&#x9650;&#x5236;&#x9009;&#x62E9;&#xFF0C;&#x6700;&#x7EC8;&#x53EF;&#x80FD;&#x6709;&#x635F;&#x6B27;&#x6D32;&#x4E58;&#x5BA2;&#x7684;&#x5229;&#x76CA;&#x3002;</p><p>&#x201C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8DB3;&#x591F;&#x7684;&#x8865;&#x6551;&#x63AA;&#x65BD;&#xFF0C;&#x8FD9;&#x4E00;&#x5408;&#x5E76;&#x5C06;&#x5BFC;&#x81F4;&#x4FDD;&#x8BC1;&#x4E58;&#x5BA2;&#x5B89;&#x5168;&#x4EE5;&#x53CA;&#x7528;&#x4E8E;&#x4E0B;&#x4E00;&#x4EE3;&#x9AD8;&#x901F;&#x5217;&#x8F66;&#x7684;&#x4FE1;&#x53F7;&#x7CFB;&#x7EDF;&#x4EF7;&#x683C;&#x4E0A;&#x6DA8;&#xFF0C;&#x201D;&#x7EF4;&#x65AF;&#x7279;&#x683C;&#x8868;&#x793A;&#x3002;&#x5979;&#x8865;&#x5145;&#x79F0;&#xFF1A;&#x201C;&#x4E24;&#x5BB6;&#x516C;&#x53F8;&#x4E0D;&#x613F;&#x610F;&#x5E94;&#x5BF9;&#x6211;&#x4EEC;&#x4E25;&#x91CD;&#x7684;&#x7ADE;&#x4E89;&#x62C5;&#x5FE7;&#x3002;&#x201D;</p><p>&#x8FD9;&#x4E00;&#x5426;&#x51B3;&#x5C06;&#x52A0;&#x5267;&#x4E00;&#x573A;&#x957F;&#x671F;&#x8FA9;&#x8BBA;&#xFF0C;&#x7126;&#x70B9;&#x95EE;&#x9898;&#x662F;&#x6B27;&#x76DF;&#x4E25;&#x683C;&#x7684;&#x53CD;&#x5784;&#x65AD;&#x89C4;&#x5219;&#x662F;&#x5426;&#x9700;&#x8981;&#x66F4;&#x65B0;&#xFF0C;&#x4EE5;&#x4FBF;&#x8BA9;&#x6B27;&#x76DF;&#x4F01;&#x4E1A;&#x4E0E;&#x7531;&#x56FD;&#x5BB6;&#x652F;&#x6301;&#x7684;&#x4E2D;&#x56FD;&#x4F01;&#x4E1A;&#x5C55;&#x5F00;&#x7ADE;&#x4E89;&#x3002;&#x5728;&#x5404;&#x81EA;&#x653F;&#x5E9C;&#x7684;&#x652F;&#x6301;&#x4E0B;&#xFF0C;&#x897F;&#x95E8;&#x5B50;&#x548C;&#x963F;&#x5C14;&#x65AF;&#x901A;&#x8868;&#x793A;&#xFF0C;&#x5408;&#x5E76;&#x5176;&#x94C1;&#x8DEF;&#x4E1A;&#x52A1;&#x5BF9;&#x4E8E;&#x62B5;&#x5FA1;&#x6765;&#x81EA;&#x4E2D;&#x56FD;&#x4E2D;&#x8F66;(CRRC)&#x7684;&#x7ADE;&#x4E89;&#x662F;&#x5FC5;&#x8981;&#x7684;&#xFF1B;&#x540E;&#x8005;&#x662F;&#x4E16;&#x754C;&#x6700;&#x5927;&#x7684;&#x94C1;&#x8DEF;&#x8F66;&#x8F86;&#x5236;&#x9020;&#x5546;&#x3002;</p><p>&#x7136;&#x800C;&#xFF0C;&#x7ADE;&#x4E89;&#x5B98;&#x5458;&#x4EEC;&#x5F97;&#x51FA;&#x7ED3;&#x8BBA;&#x8BA4;&#x4E3A;&#xFF0C;&#x4E2D;&#x56FD;&#x4F01;&#x4E1A;&#x4E0D;&#x592A;&#x53EF;&#x80FD;&#x5F88;&#x5FEB;&#x5728;&#x6B27;&#x6D32;&#x9500;&#x552E;&#x706B;&#x8F66;&#xFF0C;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x6B27;&#x76DF;&#x4E25;&#x683C;&#x7684;&#x53CD;&#x5784;&#x65AD;&#x89C4;&#x5219;&#x8981;&#x6C42;&#x8FD9;&#x4E24;&#x5BB6;&#x516C;&#x53F8;&#x51FA;&#x552E;&#x53EF;&#x89C2;&#x7684;&#x706B;&#x8F66;&#x548C;&#x4FE1;&#x53F7;&#x8D44;&#x4EA7;&#x3002;</p><p>&#x6CD5;&#x56FD;&#x8D22;&#x653F;&#x90E8;&#x957F;&#x5E03;&#x9C81;&#x8BFA;&#x2022;&#x52D2;&#x6885;&#x5C14;(Bruno Le Maire)&#x5F62;&#x5BB9;&#x7EF4;&#x65AF;&#x7279;&#x683C;&#x7684;&#x51B3;&#x5B9A;&#x201C;&#x662F;&#x4E00;&#x4E2A;&#x653F;&#x6CBB;&#x9519;&#x8BEF;&#xFF1A;&#x6B27;&#x76DF;&#x59D4;&#x5458;&#x4F1A;&#x7684;&#x804C;&#x8D23;&#x662F;&#x634D;&#x536B;&#x6B27;&#x6D32;&#x7684;&#x7ECF;&#x6D4E;&#x5229;&#x76CA;&#x2026;&#x2026;&#x62D2;&#x7EDD;&#x963F;&#x5C14;&#x65AF;&#x901A;&#x4E0E;&#x897F;&#x95E8;&#x5B50;&#x5408;&#x5E76;&#x5C06;&#x6709;&#x5229;&#x4E8E;&#x4E2D;&#x56FD;&#x7684;&#x7ECF;&#x6D4E;&#x548C;&#x4EA7;&#x4E1A;&#x5229;&#x76CA;&#x201D;&#x3002;&#x8FD9;&#x4E9B;&#x60C5;&#x7EEA;&#x5F97;&#x5230;&#x5FB7;&#x56FD;&#x7ECF;&#x6D4E;&#x90E8;&#x957F;&#x5F7C;&#x5F97;&#x2022;&#x963F;&#x5C14;&#x7279;&#x8FC8;&#x5C14;(Peter Altmaier)&#x7684;&#x547C;&#x5E94;&#xFF0C;&#x4ED6;&#x547C;&#x5401;&#x4FEE;&#x6539;&#x6B27;&#x76DF;&#x7ADE;&#x4E89;&#x89C4;&#x5219;&#xFF0C;&#x4F7F;&#x5927;&#x578B;&#x5E76;&#x8D2D;&#x4EA4;&#x6613;&#x53D8;&#x5F97;&#x66F4;&#x52A0;&#x5BB9;&#x6613;&#x3002;</p><p>&#x897F;&#x95E8;&#x5B50;&#x5468;&#x4E09;&#x8868;&#x793A;&#x4E86;&#x5931;&#x671B;&#x3002;&#x201C;&#x4FDD;&#x62A4;&#x672C;&#x5730;&#x987E;&#x5BA2;&#x5229;&#x76CA;&#x7EDD;&#x4E0D;&#x80FD;&#x610F;&#x5473;&#x7740;&#x6B27;&#x6D32;&#x65E0;&#x6CD5;&#x4E0E;&#x4E2D;&#x56FD;&#x3001;&#x7F8E;&#x56FD;&#x7B49;&#x9886;&#x5148;&#x56FD;&#x5BB6;&#x540C;&#x5904;&#x4E00;&#x4E2A;&#x516C;&#x5E73;&#x7684;&#x7ADE;&#x4E89;&#x73AF;&#x5883;&#xFF0C;&#x201D;&#x8BE5;&#x516C;&#x53F8;&#x9996;&#x5E2D;&#x6267;&#x884C;&#x5B98;&#x51EF;&#x98D2;(Joe Kaeser)&#x8868;&#x793A;&#x3002;</p><p>&#x963F;&#x5C14;&#x65AF;&#x901A;&#x8868;&#x793A;&#xFF0C;&#x8FD9;&#x5BF9;&#x4E8E;&#x6B27;&#x6D32;&#x5DE5;&#x4E1A;&#x662F;&#x4E00;&#x4E2A;&#x201C;&#x660E;&#x663E;&#x7684;&#x632B;&#x6298;&#x201D;&#x3002;&#x963F;&#x5C14;&#x65AF;&#x901A;&#x9996;&#x5E2D;&#x6267;&#x884C;&#x5B98;&#x4EA8;&#x5229;&#x2022;&#x6CE2;&#x5E15;-&#x62C9;&#x6CD5;&#x57FA;(Henri Poupart-Lafarge)&#x8868;&#x793A;&#xFF1A;&#x201C;&#x5982;&#x679C;&#x8BF4;&#x6211;&#x6709;&#x4E00;&#x4E2A;&#x9057;&#x61BE;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x6211;&#x7528;&#x4E86;&#x2018;&#x6B27;&#x6D32;&#x51A0;&#x519B;&#x4F01;&#x4E1A;&#x2019;&#x8FD9;&#x4E2A;&#x77ED;&#x8BED;&#x3002;&#x201D;</p><p>&#x7136;&#x800C;&#xFF0C;&#x82F1;&#x56FD;&#x3001;&#x897F;&#x73ED;&#x7259;&#x3001;&#x8377;&#x5170;&#x548C;&#x6BD4;&#x5229;&#x65F6;&#x7684;&#x56FD;&#x5BB6;&#x76D1;&#x7BA1;&#x673A;&#x6784;&#x4E00;&#x81F4;&#x516C;&#x5F00;&#x8868;&#x793A;&#x8FD9;&#x4E24;&#x5BB6;&#x516C;&#x53F8;&#x63D0;&#x8BAE;&#x7684;&#x8865;&#x6551;&#x63AA;&#x65BD;&#x8FDC;&#x8FDC;&#x4E0D;&#x591F;&#xFF0C;&#x5E76;&#x5BF9;&#x8FD9;&#x4E00;&#x5426;&#x51B3;&#x8868;&#x793A;&#x6B22;&#x8FCE;&#x3002;&#x8D1F;&#x8D23;&#x76D1;&#x7BA1;&#x82F1;&#x56FD;&#x94C1;&#x8DEF;&#x7684;&#x82F1;&#x56FD;&#x94C1;&#x8DEF;&#x76D1;&#x7BA1;&#x529E;&#x516C;&#x5BA4;(Office of Rail Regulation)&#x8868;&#x793A;&#xFF1A;&#x201C;&#x6211;&#x4EEC;&#x4ECE;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x660E;&#x786E;&#x8868;&#x793A;&#xFF0C;&#x8FD9;&#x6B21;&#xFF08;&#x5408;&#x5E76;&#xFF09;&#x5BF9;&#x82F1;&#x56FD;&#x4E58;&#x5BA2;&#x3001;&#x8D27;&#x8FD0;&#x5BA2;&#x6237;&#x548C;&#x7EB3;&#x7A0E;&#x4EBA;&#x6765;&#x8BF4;&#x90FD;&#x662F;&#x4E00;&#x7B14;&#x7CDF;&#x7CD5;&#x7684;&#x4EA4;&#x6613;&#x3002;&#x201D;</p><p>&#x667A;&#x5E93;&#x5E03;&#x9C81;&#x76D6;&#x5C14;(Bruegel)&#x7684;&#x8BBF;&#x95EE;&#x7814;&#x7A76;&#x5458;&#x9A6C;&#x4FEE;&#x2022;&#x6D77;&#x59C6;(Mathew Heim)&#x8BF4;&#xFF1A;&#x201C;&#x652F;&#x6301;&#x6B27;&#x6D32;&#x51A0;&#x519B;&#x4F01;&#x4E1A;&#x4E0D;&#x662F;&#x6B27;&#x6D32;&#x7ADE;&#x4E89;&#x6CD5;&#x5F8B;&#x7684;&#x804C;&#x80FD;&#x3002;</p><p>&#x201C;&#x76F8;&#x53CD;&#xFF0C;&#x6B27;&#x6D32;&#x9700;&#x8981;&#x4E00;&#x9879;&#x8FDE;&#x8D2F;&#x7684;&#x8BA1;&#x5212;&#xFF0C;&#x4EE5;&#x57F9;&#x80B2;&#x5728;&#x5168;&#x7403;&#x7ADE;&#x4E89;&#x73AF;&#x5883;&#x4E0B;&#x80FD;&#x591F;&#x84EC;&#x52C3;&#x53D1;&#x5C55;&#x3001;&#x800C;&#x65E0;&#x9700;&#x8BC9;&#x8BF8;&#x4FDD;&#x62A4;&#x4E3B;&#x4E49;&#x7684;&#x5173;&#x952E;&#x6B27;&#x6D32;&#x4EA7;&#x4E1A;&#x3002;&#x201D;</p><p>&#x897F;&#x95E8;&#x5B50;-&#x963F;&#x5C14;&#x65AF;&#x901A;&#x63D0;&#x8BAE;&#x5408;&#x5E76;&#x4E4B;&#x9645;&#xFF0C;&#x6B27;&#x6D32;&#x6B63;&#x5904;&#x4E8E;&#x4E00;&#x4E2A;&#x653F;&#x6CBB;&#x8FC7;&#x6E21;&#x671F;&#x3002;&#x4ECA;&#x5E74;5&#x6708;&#x7684;&#x6B27;&#x76DF;&#x9009;&#x4E3E;&#xFF0C;&#x4EE5;&#x53CA;&#x4ECA;&#x5E74;&#x5E03;&#x9C81;&#x585E;&#x5C14;&#x9886;&#x5BFC;&#x5C42;&#x7684;&#x53D8;&#x52A8;&#xFF0C;&#x53EF;&#x80FD;&#x5E26;&#x6765;&#x6539;&#x9769;&#x7ADE;&#x4E89;&#x653F;&#x7B56;&#x7684;&#x673A;&#x4F1A;&#x3002;</p><p>&#x6B27;&#x6D32;&#x53CD;&#x5784;&#x65AD;&#x4E3B;&#x7BA1;&#x627F;&#x8BA4;&#x4E2D;&#x56FD;&#x56FD;&#x6709;&#x4F01;&#x4E1A;&#x6784;&#x6210;&#x7ECF;&#x6D4E;&#x5A01;&#x80C1;&#xFF0C;&#x540C;&#x65F6;&#x4E3A;&#x7ADE;&#x4E89;&#x89C4;&#x5219;&#x505A;&#x4E86;&#x8FA9;&#x62A4;&#x2014;&#x2014;&#x5979;&#x8FA9;&#x79F0;&#xFF0C;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x5E2E;&#x52A9;&#x6B27;&#x76DF;&#x516C;&#x53F8;&#x4FDD;&#x6301;&#x521B;&#x65B0;&#x80FD;&#x529B;&#x548C;&#x56FD;&#x9645;&#x7ADE;&#x4E89;&#x529B;&#x3002;</p><p>&#x7EF4;&#x65AF;&#x7279;&#x683C;&#x6307;&#x51FA;&#xFF0C;&#x6B27;&#x76DF;&#x6709;&#x5176;&#x4ED6;&#x624B;&#x6BB5;&#x6765;&#x5236;&#x5B9A;&#x4EA7;&#x4E1A;&#x653F;&#x7B56;&#xFF0C;&#x5982;&#x5916;&#x6765;&#x6295;&#x8D44;&#x7B5B;&#x67E5;&#x3001;&#x53CD;&#x8865;&#x8D34;&#x4E0E;&#x8D38;&#x6613;&#x9632;&#x5FA1;&#x63AA;&#x65BD;&#xFF0C;&#x4EE5;&#x53CA;&#x63A8;&#x52A8;&#x5C01;&#x95ED;&#x7684;&#x5E02;&#x573A;&#x63D0;&#x4F9B;&#x4E92;&#x60E0;&#x51C6;&#x5165;&#x3002;</p><p>&#x963F;&#x5C14;&#x65AF;&#x901A;&#x7684;&#x6CE2;&#x5E15;-&#x62C9;&#x6CD5;&#x57FA;&#x5468;&#x4E8C;&#x544A;&#x8BC9;&#x300A;&#x8D39;&#x52A0;&#x7F57;&#x62A5;&#x300B;(Le Figaro)&#xFF0C;&#x4E0D;&#x4F1A;&#x7B2C;&#x4E8C;&#x6B21;&#x5C1D;&#x8BD5;&#x5408;&#x5E76;&#xFF0C;&#x4E24;&#x5BB6;&#x516C;&#x53F8;&#x4ECA;&#x540E;&#x5C06;&#x5404;&#x8D70;&#x5404;&#x7684;&#x8DEF;&#x3002;</p><p><i>&#x5E15;&#x7279;&#x91CC;&#x514B;&#x2022;&#x9EA6;&#x5409;(Patrick McGee)&#x6CD5;&#x5170;&#x514B;&#x798F;&#x3001;&#x6234;&#x7EF4;&#x2022;&#x57FA;&#x5965;&#x6069;(David Keohane)&#x5DF4;&#x9ECE;&#x8865;&#x5145;&#x62A5;&#x9053;</i></p><p>&#x8BD1;&#x8005;/&#x548C;&#x98CE;</p></div></div>",
  "author": "罗谢尔•托普兰斯基",
  "date_published": "2019-01-02T06:21:00.000Z",
  "lead_image_url": "http://i.ftimg.net/picture/7/000083507_piclink.jpg",
  "dek": "欧盟反垄断专员没有接受西门子和阿尔斯通提出的合并理由,即这次合并对于欧洲企业与中国国有竞争对手展开竞争是必要的。",
  "next_page_url": null,
  "url": null,
  "domain": null,
  "excerpt": null,
  "word_count": null,
  "direction": null,
  "total_pages": 1,
  "rendered_pages": 1
}

Can be reproduced via using qdaily extractor too.

@adampash
Copy link
Contributor

@HenryQW Thanks for the PR! I want to make sure we resolve #263 before proceeding with this. And if you have any thoughts on that bug, I'm all ears.

@benubois
Copy link
Contributor

I've been looking into character encoding. I think cheerio encodes all entities when calling $.html() by default. The advantage of this is that the output from mercury is less prone to passing on XSS vulnerabilities. The disadvantage is that unrelated characters get converted to entities as well i.e.

德 => &#x5FB7;

In order to not encode all entities, the cleanAndReturnNode function would need to get changed from this:

return normalizeSpaces($.html(node));

To this:

return normalizeSpaces($.html(node, { decodeEntities: false }));

In my use of mercury, I sanitize the output from mercury so this would be fine, but I'm guessing mercury wants to not pass on executable javascript?

I saw that another project switched to JSDOM to avoid this. Not sure if that would be a suitable replacement for mercury.

/cc @adampash

@HenryQW
Copy link
Author

HenryQW commented Feb 12, 2019

@benubois thanks for the input, this reminds that I did use this method in my other project and it works flawlessly.

https://github.com/HenryQW/api.henry.wang/blob/12d4ac330ca8b796fb1ce0f743579394b779352e/controllers/fullTextController.js#L8-L10

Unfortunately, JSDOM is less performant than cheerio from my past experience.

@adampash
Copy link
Contributor

adampash commented Feb 13, 2019

In my use of mercury, I sanitize the output from mercury so this would be fine, but I'm guessing mercury wants to not pass on executable javascript?

Actually, I think this is probably fine. Mercury sanitizes tags and attributes, and it looks like you're right, this could fix a lot o these problems.

If someone wants to submit a PR with a test that adds the { decodeEntities: false } bit, I think we can comfortably merge.

I should also follow up to say that if you do happen to see any significant security vulnerabilities in doing so, I'm all ears.

@HenryQW
Copy link
Author

HenryQW commented Feb 13, 2019

@adampash adding { decodeEntities: false } to cheerio.load suggested by you in src/resource/index.js

https://github.com/postlight/mercury-parser/blob/e033835c7287904371371f922c487e6d0d7d7db8/src/resource/index.js#L63-L79 will skip the decoding of ', which results in

Helter Shelter: NYC&apos;s Fallout Shelters Basically Don&apos;t Exist Anymore 

other than

Helter Shelter: NYC's Fallout Shelters Basically Don't Exist Anymore

@adampash
Copy link
Contributor

@adampash adding { decodeEntities: false } to cheerio.load suggested by you in src/resource/index.js

I think we want to keep that cheerio.load call the same. I believe it's the double-decoding that's caused problems? And that's where @benubois suggested passing the decodeEntities option above.

@HenryQW
Copy link
Author

HenryQW commented Feb 13, 2019

I did change that but it has no effect on Chinese characters.

@benubois
Copy link
Contributor

benubois commented Feb 13, 2019

@adampash I've come to believe that {decodeEntities: false} is necessary on both cheerio.load and $.html(). I think with this combination, cheerio leaves encoding/decoding alone. See where cheerio firsts encodes and then where it encodes again on output

Here's my pull request addressing this.

@HenryQW
Copy link
Author

HenryQW commented Feb 18, 2019

There is another solution for Chinese, see https://github.com/HenryQW/OpenCC.henry.wang/blob/master/route.js#L7-L21

Not sure how would this merge into mercury-parser though, probably as a middleware?

@postlight-org
Copy link
Collaborator

🤖 Automated Parsing Preview 🤖

Commit: Merge branch 'master' into extractor/ftchinese

Screenshot of fixture (this embed should work after repo is public)

Original Article | HTML Fixture | Parsed Content Preview

Parsed JSON
{
  "title": "英国认为华为风险可控",
  "content": "<div><div id=\"story-body-container\"> <p>&#x82F1;&#x56FD;&#x653F;&#x5E9C;&#x5F97;&#x51FA;&#x7ED3;&#x8BBA;&#x8BA4;&#x4E3A;&#xFF0C;&#x5B83;&#x80FD;&#x591F;&#x7F13;&#x89E3;&#x5728;5G&#x7F51;&#x7EDC;&#x4E2D;&#x4F7F;&#x7528;&#x534E;&#x4E3A;(Huawei)&#x8BBE;&#x5907;&#x7684;&#x98CE;&#x9669;&#x3002;&#x8FD9;&#x4E2A;&#x7ED3;&#x8BBA;&#x6C89;&#x91CD;&#x6253;&#x51FB;&#x4E86;&#x7F8E;&#x56FD;&#x8BF4;&#x670D;&#x76DF;&#x56FD;&#x628A;&#x534E;&#x4E3A;&#x6321;&#x5728;&#x9AD8;&#x901F;&#x7535;&#x4FE1;&#x7CFB;&#x7EDF;&#x95E8;&#x5916;&#x7684;&#x52AA;&#x529B;&#x3002;</p><p>&#x4E24;&#x4F4D;&#x77E5;&#x60C5;&#x4EBA;&#x58EB;&#x5C06;&#x8FD9;&#x4E00;&#x5C1A;&#x672A;&#x516C;&#x5F00;&#x7684;&#x7ED3;&#x8BBA;&#x544A;&#x8BC9;&#x82F1;&#x56FD;&#x300A;&#x91D1;&#x878D;&#x65F6;&#x62A5;&#x300B;&#xFF0C;&#x79F0;&#x82F1;&#x56FD;&#x56FD;&#x5BB6;&#x7F51;&#x7EDC;&#x5B89;&#x5168;&#x4E2D;&#x5FC3;(National Cyber Security Centre, NCSC)&#x8BA4;&#x5B9A;&#xFF0C;&#x6709;&#x529E;&#x6CD5;&#x9650;&#x5236;&#x5728;&#x672A;&#x6765;5G&#x8D85;&#x9AD8;&#x901F;&#x7F51;&#x7EDC;&#x4E2D;&#x4F7F;&#x7528;&#x534E;&#x4E3A;&#x8BBE;&#x5907;&#x7684;&#x98CE;&#x9669;&#x3002;</p><p>&#x8FD9;&#x4E00;&#x7ED3;&#x8BBA;&#x51FA;&#x7089;&#x4E4B;&#x9645;&#xFF0C;&#x7F8E;&#x56FD;&#x6B63;&#x52A0;&#x7D27;&#x52AA;&#x529B;&#x8BF4;&#x670D;&#x76DF;&#x56FD;&#x7981;&#x6B62;&#x534E;&#x4E3A;&#x53C2;&#x4E0E;&#x7535;&#x4FE1;&#x7F51;&#x7EDC;&#x5EFA;&#x8BBE;&#xFF0C;&#x7406;&#x7531;&#x662F;&#x8FD9;&#x5BB6;&#x4E2D;&#x56FD;&#x4F9B;&#x5E94;&#x5546;&#x53EF;&#x80FD;&#x5E2E;&#x52A9;&#x4E2D;&#x56FD;&#x653F;&#x5E9C;&#x4ECE;&#x4E8B;&#x95F4;&#x8C0D;&#x6D3B;&#x52A8;&#x6216;&#x7F51;&#x7EDC;&#x7834;&#x574F;&#x3002;</p><p>&#x7F8E;&#x56FD;&#x56FD;&#x5BB6;&#x5B89;&#x5168;&#x5C40;(NSA)&#x8FD1;&#x6765;&#x4E0E;&#x76DF;&#x53CB;&#x548C;&#x5408;&#x4F5C;&#x4F19;&#x4F34;&#x5206;&#x4EAB;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#x4EE5;&#x5F3A;&#x8C03;&#x76F8;&#x5173;&#x98CE;&#x9669;&#xFF0C;&#x4F46;&#x662F;&#x6570;&#x4E2A;&#x6B27;&#x6D32;&#x56FD;&#x5BB6;&#xFF08;&#x5305;&#x62EC;&#x82F1;&#x56FD;&#x548C;&#x5FB7;&#x56FD;&#xFF09;&#x5E76;&#x672A;&#x88AB;&#x8BF4;&#x670D;&#x9700;&#x8981;&#x5B9E;&#x65BD;&#x7981;&#x4EE4;&#x3002;</p><p>&#x4E00;&#x4F4D;&#x719F;&#x6089;&#x76F8;&#x5173;&#x4E89;&#x8BBA;&#x7684;&#x4EBA;&#x58EB;&#x8868;&#x793A;&#xFF0C;&#x82F1;&#x56FD;&#x7684;&#x7ED3;&#x8BBA;&#x5BF9;&#x6B27;&#x6D32;&#x5404;&#x56FD;&#x9886;&#x5BFC;&#x4EBA;&#x5C06;&#x201C;&#x6709;&#x5F88;&#x5927;&#x5206;&#x91CF;&#x201D;&#xFF0C;&#x56E0;&#x4E3A;&#x82F1;&#x56FD;&#x662F;&#x4E94;&#x773C;&#x8054;&#x76DF;(Five Eyes)&#x60C5;&#x62A5;&#x5206;&#x4EAB;&#x7F51;&#x7EDC;&#x7684;&#x6210;&#x5458;&#xFF0C;&#x53EF;&#x4EE5;&#x83B7;&#x5F97;&#x654F;&#x611F;&#x7684;&#x7F8E;&#x56FD;&#x60C5;&#x62A5;&#x3002;</p><p>&#x201C;&#x5176;&#x4ED6;&#x56FD;&#x5BB6;&#x53EF;&#x4EE5;&#x63D0;&#x51FA;&#x8FD9;&#x6837;&#x7684;&#x8BBA;&#x70B9;&#xFF0C;&#x5373;&#x5982;&#x679C;&#x82F1;&#x56FD;&#x4EBA;&#x6709;&#x4FE1;&#x5FC3;&#x7F13;&#x89E3;&#x56FD;&#x5BB6;&#x5B89;&#x5168;&#x5A01;&#x80C1;&#xFF0C;&#x90A3;&#x4E48;&#x4ED6;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x5411;&#x56FD;&#x5185;&#x516C;&#x4F17;&#x548C;&#x7F8E;&#x56FD;&#x884C;&#x653F;&#x5F53;&#x5C40;&#x4FDD;&#x8BC1;&#xFF0C;&#x53EA;&#x8981;&#x4ED6;&#x4EEC;&#x91C7;&#x53D6;&#x4E86;&#x82F1;&#x56FD;&#x4EBA;&#x63A8;&#x8350;&#x7684;&#x5404;&#x79CD;&#x9884;&#x9632;&#x63AA;&#x65BD;&#xFF0C;&#x4ED6;&#x4EEC;&#x7EE7;&#x7EED;&#x5141;&#x8BB8;&#x56FD;&#x5185;&#x7535;&#x4FE1;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#x4F7F;&#x7528;&#x4E2D;&#x56FD;&#x7EC4;&#x4EF6;&#x5C31;&#x662F;&#x5BA1;&#x614E;&#x7684;&#xFF0C;&#x201D;&#x6B64;&#x4EBA;&#x8868;&#x793A;&#x3002;</p><p>&#x7F8E;&#x56FD;&#x63D0;&#x51FA;&#xFF0C;5G&#x7684;&#x901F;&#x5EA6;&#x5C06;&#x5982;&#x6B64;&#x4E4B;&#x5FEB;&#x2014;&#x2014;&#x5E76;&#x4E14;&#x6709;&#x5982;&#x6B64;&#x591A;&#x7684;&#x519B;&#x4E8B;&#x7528;&#x9014;&#x2014;&#x2014;&#x4EE5;&#x81F3;&#x4E8E;&#x4F7F;&#x7528;&#x4EFB;&#x4F55;&#x4E2D;&#x56FD;&#x7535;&#x4FE1;&#x8BBE;&#x5907;&#x90FD;&#x5E26;&#x6709;&#x592A;&#x9AD8;&#x7684;&#x98CE;&#x9669;&#x3002;&#x7F8E;&#x56FD;&#x5B98;&#x5458;&#x8FD8;&#x63D0;&#x51FA;&#xFF0C;&#x867D;&#x7136;&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#x53EF;&#x80FD;&#x6CA1;&#x6709;&#x6076;&#x610F;&#x6D3B;&#x52A8;&#x7684;&#x8BC1;&#x636E;&#xFF0C;&#x4F46;&#x534E;&#x4E3A;&#x53EF;&#x80FD;&#x4F1A;&#x4F7F;&#x7528;&#x6076;&#x610F;&#x8F6F;&#x4EF6;&#x66F4;&#x65B0;&#x4E3A;&#x95F4;&#x8C0D;&#x6D3B;&#x52A8;&#x521B;&#x9020;&#x6761;&#x4EF6;&#x3002;</p><p>&#x82F1;&#x56FD;&#x4FE1;&#x53F7;&#x60C5;&#x62A5;&#x673A;&#x6784;&#x2014;&#x2014;&#x653F;&#x5E9C;&#x901A;&#x4FE1;&#x603B;&#x90E8;(GCHQ)&#x524D;&#x4E3B;&#x4EFB;&#x7F57;&#x4F2F;&#x7279;&#x2022;&#x6C49;&#x5C3C;&#x6839;(Robert Hannigan)&#x6700;&#x8FD1;&#x5728;&#x82F1;&#x56FD;&#x300A;&#x91D1;&#x878D;&#x65F6;&#x62A5;&#x300B;&#x64B0;&#x6587;&#xFF0C;&#x79F0;NCSC&#x201C;&#x4ECE;&#x672A;&#x53D1;&#x73B0;&#x4EFB;&#x4F55;&#x8BC1;&#x636E;&#x8BC1;&#x660E;&#x4E2D;&#x56FD;&#x653F;&#x5E9C;&#x901A;&#x8FC7;&#x534E;&#x4E3A;&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x6076;&#x610F;&#x7F51;&#x7EDC;&#x6D3B;&#x52A8;&#x201D;&#xFF0C;&#x800C;&#x4E14;&#x201C;&#x6709;&#x5173;&#x5728;5G&#x7F51;&#x7EDC;&#x7684;&#x4EFB;&#x4F55;&#x90E8;&#x5206;&#x91C7;&#x7528;&#x4EFB;&#x4F55;&#x4E2D;&#x56FD;&#x6280;&#x672F;&#x90FD;&#x4EE3;&#x8868;&#x7740;&#x4E0D;&#x53EF;&#x63A5;&#x53D7;&#x7684;&#x98CE;&#x9669;&#x7684;&#x65AD;&#x8A00;&#x662F;&#x65E0;&#x7A3D;&#x4E4B;&#x8C08;&#x201D;&#x3002;</p><p>&#x82F1;&#x56FD;&#x7684;&#x7ED3;&#x8BBA;&#x4E0E;&#x540C;&#x4E3A;&#x4E94;&#x773C;&#x6210;&#x5458;&#x7684;&#x6FB3;&#x5927;&#x5229;&#x4E9A;&#x548C;&#x65B0;&#x897F;&#x5170;&#x5F62;&#x6210;&#x9C9C;&#x660E;&#x5BF9;&#x6BD4;&#xFF0C;&#x540E;&#x4E24;&#x56FD;&#x53BB;&#x5E74;&#x5C31;&#x5DF2;&#x7981;&#x6B62;&#x672C;&#x56FD;&#x7535;&#x4FE1;&#x63D0;&#x4F9B;&#x5546;&#x5728;5G&#x7F51;&#x7EDC;&#x4E2D;&#x4F7F;&#x7528;&#x534E;&#x4E3A;&#x8BBE;&#x5907;&#x3002;</p><p>&#x4E0E;&#x6B64;&#x540C;&#x65F6;&#xFF0C;&#x5510;&#x7EB3;&#x5FB7;&#x2022;&#x7279;&#x6717;&#x666E;(Donald Trump)&#x6B63;&#x5728;&#x8003;&#x8651;&#x53D1;&#x5E03;&#x5B9E;&#x9645;&#x4E0A;&#x5C06;&#x7981;&#x6B62;&#x7F8E;&#x56FD;&#x516C;&#x53F8;&#x4F7F;&#x7528;&#x534E;&#x4E3A;&#x8BBE;&#x5907;&#x7684;&#x884C;&#x653F;&#x547D;&#x4EE4;&#x3002;&#x719F;&#x6089;&#x8FD9;&#x9053;&#x547D;&#x4EE4;&#x7684;&#x4E00;&#x540D;&#x4EBA;&#x58EB;&#x8868;&#x793A;&#xFF0C;&#x5B83;&#x5C06;&#x4EE5;&#x201C;&#x4E0D;&#x5BF9;&#x516C;&#x53F8;&#x548C;&#x56FD;&#x5BB6;&#x70B9;&#x540D;&#x201D;&#x7684;&#x65B9;&#x5F0F;&#x5199;&#x6210;&#x3002;</p><p>&#x7F8E;&#x56FD;&#x526F;&#x603B;&#x7EDF;&#x8FC8;&#x514B;&#x2022;&#x5F6D;&#x65AF;(Mike Pence)&#x4E0A;&#x5468;&#x516D;&#x5728;&#x6155;&#x5C3C;&#x9ED1;&#x5B89;&#x5168;&#x4F1A;&#x8BAE;(Munich Security Conference)&#x4E0A;&#x53D1;&#x8868;&#x6F14;&#x8BB2;&#x65F6;&#x6307;&#x51FA;&#xFF0C;&#x7531;&#x4E8E;&#x4E2D;&#x56FD;&#x6CD5;&#x5F8B;&#x8981;&#x6C42;&#x7535;&#x4FE1;&#x516C;&#x53F8;&#x4E0E;&#x4E2D;&#x56FD;&#x653F;&#x5E9C;&#x5171;&#x4EAB;&#x6570;&#x636E;&#xFF0C;&#x56E0;&#x6B64;&#x534E;&#x4E3A;&#x6784;&#x6210;&#x5A01;&#x80C1;&#x3002;</p><p>&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x8BBA;&#x575B;&#x4E0A;&#xFF0C;&#x5317;&#x7EA6;(NATO)&#x79D8;&#x4E66;&#x957F;&#x5EF6;&#x65AF;&#x2022;&#x65AF;&#x6258;&#x5C14;&#x6ED5;&#x8D1D;&#x683C;(Jens Stoltenberg)&#x544A;&#x8BC9;&#x82F1;&#x56FD;&#x300A;&#x91D1;&#x878D;&#x65F6;&#x62A5;&#x300B;&#xFF0C;&#x5317;&#x7EA6;&#x8054;&#x76DF;&#x201C;&#x975E;&#x5E38;&#x8BA4;&#x771F;&#x5730;&#x201D;&#x5BF9;&#x5F85;&#x56F4;&#x7ED5;&#x534E;&#x4E3A;&#x7684;&#x62C5;&#x5FE7;&#xFF0C;&#x6570;&#x4E2A;&#x76DF;&#x56FD;&#x5E0C;&#x671B;&#x62FF;&#x51FA;&#x534F;&#x8C03;&#x4E00;&#x81F4;&#x7684;&#x56DE;&#x5E94;&#x3002;</p><p>&#x201C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x770B;&#x4E00;&#x770B;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x8FBE;&#x5230;&#x7684;&#x56DE;&#x5E94;&#x534F;&#x8C03;&#x6C34;&#x5E73;&#x3002;&#x6211;&#x4EEC;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x8054;&#x76DF;&#x8FD8;&#x6CA1;&#x6709;&#x5F97;&#x51FA;&#x7ED3;&#x8BBA;&#xFF0C;&#x4F46;&#x8FD9;&#x8868;&#x660E;&#x4E86;&#x9700;&#x8981;&#x5E94;&#x5BF9;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x201D;&#x4ED6;&#x8868;&#x793A;&#x3002;</p><p>&#x82F1;&#x56FD;&#x79D8;&#x5BC6;&#x60C5;&#x62A5;&#x5C40;&#xFF08;SIS&#xFF0C;&#x901A;&#x79F0;&#x201C;&#x519B;&#x60C5;&#x516D;&#x5904;&#x201D;&#xFF0C;&#x5373;MI6&#xFF09;&#x5C40;&#x957F;&#x4E9A;&#x5386;&#x514B;&#x65AF;&#x2022;&#x626C;&#x683C;(Alex Younger)&#x4E0A;&#x5468;&#x4E94;&#x8868;&#x793A;&#xFF0C;&#x82F1;&#x56FD;&#x53EF;&#x80FD;&#x4F1A;&#x5BF9;&#x534E;&#x4E3A;&#x91C7;&#x53D6;&#x6BD4;&#x7F8E;&#x56FD;&#x66F4;&#x4E3A;&#x6E29;&#x548C;&#x7684;&#x6001;&#x5EA6;&#xFF0C;&#x79F0;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x8FC7;&#x4E8E;&#x590D;&#x6742;&#xFF0C;&#x4E0D;&#x5B9C;&#x7B80;&#x5355;&#x5730;&#x5C01;&#x6740;&#x8BE5;&#x516C;&#x53F8;&#x3002;&#x4ED6;&#x8868;&#x793A;&#xFF0C;&#x8FD9;&#x662F;&#x201C;&#x4E00;&#x4E2A;&#x6BD4;&#x2018;&#x8FDB;&#x6765;&#x8FD8;&#x662F;&#x51FA;&#x53BB;&#x2019;&#x66F4;&#x52A0;&#x590D;&#x6742;&#x7684;&#x95EE;&#x9898;&#x201D;&#xFF0C;&#x800C;&#x4E14;&#x5404;&#x56FD;&#x62E5;&#x6709;&#x201C;&#x627E;&#x5230;&#x6240;&#x6709;&#x8FD9;&#x4E9B;&#x95EE;&#x9898;&#x7684;&#x7B54;&#x6848;&#x7684;&#x4E3B;&#x6743;&#x6743;&#x5229;&#x201D;&#x3002;</p><p>&#x5BF9;&#x4E8E;&#x5DF2;&#x7ECF;&#x8BA4;&#x5B9A;&#x4F7F;&#x7528;&#x534E;&#x4E3A;&#x8BBE;&#x5907;&#x7684;&#x98CE;&#x9669;&#x53EF;&#x63A7;&#x7684;&#x8BF4;&#x6CD5;&#xFF0C;NCSC&#x6CA1;&#x6709;&#x8868;&#x793A;&#x5F02;&#x8BAE;&#x3002;</p></div></div>",
  "author": null,
  "date_published": "2018-01-02T07:17:00.000Z",
  "lead_image_url": "http://i.ftimg.net/picture/3/000082493_piclink.jpg",
  "dek": "英国政府得出结论认为,能够缓解在5G网络中使用华为设备的风险。这个尚未公开的结论沉重打击美国的游说努力。",
  "next_page_url": null,
  "url": "http://www.ftchinese.com/story/001081496?full=y",
  "domain": "www.ftchinese.com",
  "word_count": 13,
  "direction": "ltr",
  "total_pages": 1,
  "rendered_pages": 1
}

null fields

  • author

  • next_page_url

3 failed tests 😱

WwwFtchineseComExtractor initial test case returns the author

See what went wrong
  AssertionError [ERR_ASSERTION]: null == '英国《金融时报》 迪米 华盛顿 , 戴维•邦德 慕尼黑报道'
    at Object.equal (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:48:14)
    at tryCatch (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:17:103)
    at _next (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:19:194)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

WwwFtchineseComExtractor initial test case returns the date_published

See what went wrong
  AssertionError [ERR_ASSERTION]: null == '2018-01-02T07:17:00.000Z'
    at Object.equal (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:61:14)
    at tryCatch (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:17:103)
    at _next (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:19:194)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

WwwFtchineseComExtractor initial test case returns the content

See what went wrong
  AssertionError [ERR_ASSERTION]: '' == '英国政府得出结论认为,它能够缓解在5G网络中使用华为(Huawei)设备的风险。这个结论沉重打击了美国说服盟国把华为挡在高速电信系统门外的努力。两位知情人士将这一尚未公开的结论告诉英国《金融时报》,称英国国家网络安全中心(National'
    at Object.equal (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:105:14)
    at tryCatch (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (/home/circleci/project/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:17:103)
    at _next (/home/circleci/project/src/extractors/custom/www.ftchinese.com/index.test.js:19:194)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

@HenryQW HenryQW closed this Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants