Fix WSJ: JSON-LD changed (#2960)

这个提交包含在:
Sebastian Karcher 2023-01-17 10:59:38 -05:00 提交者 GitHub
父节点 6b26b7a84f
当前提交 3baec8a3ef
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23

查看文件

@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2019-06-23 22:38:11"
"lastUpdated": "2023-01-14 04:48:29"
}
/*
@ -98,22 +98,35 @@ function scrape(doc, url) {
// correct this by using the JSON-LD data.
var jsonld = ZU.xpathText(doc, '//script[@type="application/ld+json"]');
if (jsonld) {
var firstContext = jsonld.indexOf("@context");
if (firstContext > 0) {
var secondContext = jsonld.indexOf("@context", firstContext + 1);
// sometimes there is a second context at the end, which makes the
// json non-valid, therefore we delete that before
// e.g. https://www.wsj.com/articles/the-turnabout-on-religious-freedom-11561155218
if (secondContext > -1) {
Z.debug("Delete second context from JSON data");
jsonld = jsonld.substr(0, secondContext - 1).replace(/[, {"]*$/, '');
}
}
var data = JSON.parse(jsonld);
if (data.creator && data.creator.length) {
item.creators = [];
for (var i = 0; i < data.creator.length; i++) {
item.creators.push(ZU.cleanAuthor(data.creator[i], "author"));
for (let i = 0; i < data.length; i++) {
if (data[i]["@type"] == "NewsArticle") {
let jsonAuthor = false;
if (data[i].author && data[i].author.length) {
jsonAuthor = true;
item.creators = [];
for (let j = 0; j < data[i].author.length; j++) {
if (data[i].author[j]["@type"] == "Person") {
item.creators.push(ZU.cleanAuthor(data[i].author[j].name, "author"));
}
else {
item.creators.push(ZU.cleanAuthor(data[i].author[j].name, "author", true));
}
}
}
if (!jsonAuthor) {
// If we don't get authors from JSON (as is the case for old articles)
// parse them from metaheader
let authorString = attr('meta[name="author"]', 'content');
if (authorString) {
item.creators = [];
let authors = authorString.split(/,?\s+and\s+|,\s+/);
for (let author of authors) {
item.creators.push(ZU.cleanAuthor(author, "author", false));
}
}
}
break;
}
}
}
@ -133,11 +146,11 @@ function scrape(doc, url) {
var testCases = [
{
"type": "web",
"url": "https://www.wsj.com/news/articles/SB10001424052970204517204577046222233016362",
"url": "https://www.wsj.com/articles/SB10001424052970204517204577046222233016362",
"items": [
{
"itemType": "newspaperArticle",
"title": "America's Jobless, Yearning for Oz",
"title": "Hundreds Say They'd Take Australian Mining Job",
"creators": [
{
"firstName": "John W.",
@ -145,26 +158,21 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2011-11-19T05:01:00.000Z",
"date": "2011-11-18T19:58:00Z",
"ISSN": "0099-9660",
"abstractNote": "A profile of an Australian miner making $200,000 a year, published in The Wall Street Journal, led hundreds of people to ask how they could apply for such a job.",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "Careers",
"url": "https://www.wsj.com/articles/SB10001424052970204517204577046222233016362",
"url": "http://online.wsj.com/article/SB10001424052970204517204577046222233016362.html",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
"economic news",
"economic performance",
"employment",
"indicators",
"unemployment"
],
"tags": [],
"notes": [],
"seeAlso": []
}
@ -172,7 +180,7 @@ var testCases = [
},
{
"type": "web",
"url": "https://www.wsj.com/news/articles/SB10001424052970203471004577144672783559392",
"url": "https://www.wsj.com/articles/SB10001424052970203471004577144672783559392",
"items": [
{
"itemType": "newspaperArticle",
@ -189,17 +197,18 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2012-01-07T05:01:00.000Z",
"date": "2012-01-06T23:20:00Z",
"ISSN": "0099-9660",
"abstractNote": "An outspoken analyst who is embroiled in the Wall Street insider-trading investigation allegedly left threatening messages for two FBI agents.",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "Markets",
"url": "https://www.wsj.com/articles/SB10001424052970203471004577144672783559392",
"url": "http://online.wsj.com/article/SB10001424052970203471004577144672783559392.html",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
@ -208,51 +217,19 @@ var testCases = [
}
]
},
{
"type": "web",
"url": "https://blogs.wsj.com/overheard/2012/01/06/the-ego-has-landed/",
"items": [
{
"itemType": "blogPost",
"title": "The Ego Has Landed",
"creators": [
{
"firstName": "Liam",
"lastName": "Denning",
"creatorType": "author"
}
],
"date": "2012-01-06T21:22:12-05:00",
"abstractNote": "In their gut, most investors know a narcissistic CEO is cause for caution. But how do you prove that? A group of academics have come up with a possible solution.",
"blogTitle": "WSJ",
"language": "en-US",
"url": "https://blogs.wsj.com/overheard/2012/01/06/the-ego-has-landed/",
"attachments": [
{
"title": "Snapshot"
}
],
"tags": [
"ceo",
"m&a"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.wsj.com/search/term.html?KEYWORDS=argentina&mod=DNH_S",
"defer": true,
"items": "multiple"
},
{
"type": "web",
"url": "https://blogs.wsj.com/economics/2012/01/07/number-of-the-week-americans-cheaper-restaurant-bills/",
"url": "https://www.wsj.com/articles/BL-REB-15488",
"items": [
{
"itemType": "blogPost",
"title": "Number of the Week: Americans Cheaper Restaurant Bills",
"itemType": "newspaperArticle",
"title": "Number of the Week: Americans' Cheaper Restaurant Bills",
"creators": [
{
"firstName": "Phil",
@ -260,15 +237,19 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2012-01-07T10:00:55-05:00",
"date": "2012-01-07T10:00:00Z",
"ISSN": "0099-9660",
"abstractNote": "Americans spend less per visit to restaurants than most other major industrialized countries, according to data compiled by market research firm NPD Group.",
"blogTitle": "WSJ",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "Real Time Economics",
"shortTitle": "Number of the Week",
"url": "https://blogs.wsj.com/economics/2012/01/07/number-of-the-week-americans-cheaper-restaurant-bills/",
"url": "https://www.wsj.com/articles/BL-REB-15488",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
@ -291,22 +272,38 @@ var testCases = [
"creatorType": "author"
}
],
"date": "2014-09-07T01:37:00.000Z",
"date": "2014-09-07T01:37:00Z",
"ISSN": "0099-9660",
"abstractNote": "Matthew Miller, one of three Americans detained by North Korea, will face trial next Sunday, the country's state media said.",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "World",
"url": "https://www.wsj.com/articles/american-detained-in-north-korea-to-face-trial-next-sunday-1410053845",
"url": "http://online.wsj.com/articles/american-detained-in-north-korea-to-face-trial-next-sunday-1410053845",
"attachments": [
{
"title": "Snapshot"
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "Matthew Miller"
"tag": "Crime/Courts"
},
{
"tag": "OASN"
},
{
"tag": "ONEW"
},
{
"tag": "Political/General News"
},
{
"tag": "SYND"
},
{
"tag": "World News"
},
{
"tag": "american detained in north korea"
@ -330,16 +327,193 @@ var testCases = [
"tag": "north korea"
},
{
"tag": "oasn"
"tag": "political"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.wsj.com/articles/faa-suffers-glitch-to-crew-alert-system-potentially-affecting-flights-in-u-s-11673437407?mod=hp_lead_pos1",
"items": [
{
"itemType": "newspaperArticle",
"title": "U.S. Flight Disruptions Mount After FAA Grounding Order Ends ",
"creators": [
{
"firstName": "Andrew",
"lastName": "Tangel",
"creatorType": "author"
},
{
"tag": "onew"
"firstName": "Alison",
"lastName": "Sider",
"creatorType": "author"
},
{
"firstName": "Benjamin",
"lastName": "Katz",
"creatorType": "author"
}
],
"date": "2023-01-11T11:43:00Z",
"ISSN": "0099-9660",
"abstractNote": "The Federal Aviation Administration lifted its ban on domestic flight departures across the U.S. following an overnight outage.",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "Business",
"url": "https://www.wsj.com/articles/faa-suffers-glitch-to-crew-alert-system-potentially-affecting-flights-in-u-s-11673437407",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "AAL"
},
{
"tag": "Air Transport"
},
{
"tag": "Airlines"
},
{
"tag": "American Airlines Group"
},
{
"tag": "Automotive"
},
{
"tag": "Business/Disruptive Innovation"
},
{
"tag": "C&E Industry News Filter"
},
{
"tag": "Content Types"
},
{
"tag": "Corporate/Industrial News"
},
{
"tag": "DAL"
},
{
"tag": "Delta Air Lines"
},
{
"tag": "FDX"
},
{
"tag": "Factiva Filters"
},
{
"tag": "FedEx"
},
{
"tag": "JBLU"
},
{
"tag": "JetBlue Airways"
},
{
"tag": "LUV"
},
{
"tag": "Low Cost Airlines"
},
{
"tag": "Passenger Airlines"
},
{
"tag": "Political/General News"
},
{
"tag": "Product/Service Disruptions"
},
{
"tag": "Products/Services"
},
{
"tag": "Regulation/Government Policy"
},
{
"tag": "SYND"
},
{
"tag": "Southwest Airlines"
},
{
"tag": "Transport"
},
{
"tag": "Transportation/Logistics"
},
{
"tag": "UAL"
},
{
"tag": "United Airlines Holdings"
},
{
"tag": "WSJ-PRO-WSJ.com"
},
{
"tag": "business"
},
{
"tag": "corporate"
},
{
"tag": "disruptive innovation"
},
{
"tag": "general news"
},
{
"tag": "gfx-contrib"
},
{
"tag": "government policy"
},
{
"tag": "industrial news"
},
{
"tag": "logistics"
},
{
"tag": "political"
},
{
"tag": "world news"
"tag": "product"
},
{
"tag": "products"
},
{
"tag": "regulation"
},
{
"tag": "service disruptions"
},
{
"tag": "services"
},
{
"tag": "transportation"
},
{
"tag": "wsjcorp"
},
{
"tag": "wsjspeeddesk"
}
],
"notes": [],