-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathWall Street Journal.js
525 lines (509 loc) · 11.9 KB
/
Wall Street Journal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
{
"translatorID": "53f8d182-4edc-4eab-b5a1-141698a1303b",
"label": "Wall Street Journal",
"creator": "Philipp Zumstein",
"target": "^https?://(online|blogs|www)?\\.wsj\\.com/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-01-14 04:48:29"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2016 Philipp Zumstein
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (url.includes('blogs.wsj.com')) {
return "blogPost";
}
else if (url.includes('articles')) {
return "newspaperArticle";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//h3[contains(@class, "headline")]/a');
for (var i = 0; i < rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) return;
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
}
else {
scrape(doc, url);
}
}
function scrape(doc, url) {
var translator = Zotero.loadTranslator('web');
var type = detectWeb(doc, url);
// Embedded Metadata
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
translator.setHandler('itemDone', function (obj, item) {
item.ISSN = "0099-9660";
item.language = "en-US";
if (type == "newspaperArticle") {
item.publicationTitle = "Wall Street Journal";
}
// Multiple authors are not seperated into multiple metadata fields
// and will therefore be extracted wrongly into one author. We
// correct this by using the JSON-LD data.
var jsonld = ZU.xpathText(doc, '//script[@type="application/ld+json"]');
if (jsonld) {
var data = JSON.parse(jsonld);
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;
}
}
}
item.complete();
});
translator.getTranslatorObject(function (trans) {
trans.itemType = type;
trans.addCustomFields({
"article.published": "date"
});
trans.doWeb(doc, url);
});
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://www.wsj.com/articles/SB10001424052970204517204577046222233016362",
"items": [
{
"itemType": "newspaperArticle",
"title": "Hundreds Say They'd Take Australian Mining Job",
"creators": [
{
"firstName": "John W.",
"lastName": "Miller",
"creatorType": "author"
}
],
"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": "http://online.wsj.com/article/SB10001424052970204517204577046222233016362.html",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.wsj.com/articles/SB10001424052970203471004577144672783559392",
"items": [
{
"itemType": "newspaperArticle",
"title": "An Odd Turn in Insider Case",
"creators": [
{
"firstName": "Jenny",
"lastName": "Strasburg",
"creatorType": "author"
},
{
"firstName": "Susan",
"lastName": "Pulliam",
"creatorType": "author"
}
],
"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": "http://online.wsj.com/article/SB10001424052970203471004577144672783559392.html",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"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://www.wsj.com/articles/BL-REB-15488",
"items": [
{
"itemType": "newspaperArticle",
"title": "Number of the Week: Americans' Cheaper Restaurant Bills",
"creators": [
{
"firstName": "Phil",
"lastName": "Izzo",
"creatorType": "author"
}
],
"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.",
"language": "en-US",
"libraryCatalog": "www.wsj.com",
"publicationTitle": "Wall Street Journal",
"section": "Real Time Economics",
"shortTitle": "Number of the Week",
"url": "https://www.wsj.com/articles/BL-REB-15488",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://www.wsj.com/articles/american-detained-in-north-korea-to-face-trial-next-sunday-1410053845",
"items": [
{
"itemType": "newspaperArticle",
"title": "American Detained in North Korea to Face Trial Next Sunday",
"creators": [
{
"firstName": "Jeyup S.",
"lastName": "Kwaak",
"creatorType": "author"
}
],
"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": "http://online.wsj.com/articles/american-detained-in-north-korea-to-face-trial-next-sunday-1410053845",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "Crime/Courts"
},
{
"tag": "OASN"
},
{
"tag": "ONEW"
},
{
"tag": "Political/General News"
},
{
"tag": "SYND"
},
{
"tag": "World News"
},
{
"tag": "american detained in north korea"
},
{
"tag": "american in north korea"
},
{
"tag": "courts"
},
{
"tag": "crime"
},
{
"tag": "general news"
},
{
"tag": "matthew miller"
},
{
"tag": "north korea"
},
{
"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"
},
{
"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": "product"
},
{
"tag": "products"
},
{
"tag": "regulation"
},
{
"tag": "service disruptions"
},
{
"tag": "services"
},
{
"tag": "transportation"
},
{
"tag": "wsjcorp"
},
{
"tag": "wsjspeeddesk"
}
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/