-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.js
226 lines (224 loc) · 6.89 KB
/
news.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
module.exports = {
// Crawl these pages first when the application starts up
initialURLs: [
"https://www.bbc.co.uk/news",
"https://www.theguardian.com/uk",
"https://news.sky.com/",
"https://www.politico.eu/?no-geo-redirect",
"https://apnews.com/",
"https://www.dw.com/en/"
],
rulesets: [
{ // BBC News home page - find links to articles
pattern: /^https?\:\/\/www\.bbc\.co\.uk\/news$/i,
linkDiscovery: {
enabled: true, // Save links in the database
crawlDiscovered: true, // And add those links to the crawl queue
internalOnly: true, // Only save & crawl links that have the same base URL as the page they were found on
pattern: /^https?\:\/\/www\.bbc\.co\.uk\/news\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\d+$/i // Only look for links with this pattern
},
media: {
enabled: false // Don't extract any images from the page
},
recrawl: true // Re-crawl this page after recrawlInterval (see the bottom of this file)
},
{ // BBC article pages
pattern: /^https?\:\/\/www\.bbc\.co\.uk\/news\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\d+$/i, // This matches the pages for the links found on the ruleset above in linkDiscovery.pattern (i.e. news pages)
linkDiscovery: {
enabled: false // Don't save links from these pages
},
media: {
enabled: false // Don't extract any images from the page
},
recrawl: false, // Don't re-crawl this page
structuredContent: { // Structured content is saved in the database. The row for this entry will contain a JSON datastructure with "title" and "body" properties, and the values will be set by extracting content from the DOM selectors on the page below.
title: {
type: "string",
selector: "h1#main-heading"
},
body: {
type: "string",
selector: "#main-content article"
}
}
},
{ // Guardian home page - find links to articles
pattern: /^https?\:\/\/www\.theguardian\.com\/uk$/i,
linkDiscovery: {
enabled: true,
crawlDiscovered: true,
internalOnly: true,
pattern: /^https?\:\/\/www\.theguardian\.com\/[\w+\d+\-]+\/\d{4}\/\w{3}\/\d{2}\/([a-z][a-z0-9]*)(-[a-z0-9]+)+$/i // /category/live (optional)/year/month/day/title
},
media: {
enabled: false
},
recrawl: true
},
{ // Guardian article pages
pattern: /^https?\:\/\/www\.theguardian\.com\/[\w+\d+\-]+\/\d{4}\/\w{3}\/\d{2}\/([a-z][a-z0-9]*)(-[a-z0-9]+)+$/i,
linkDiscovery: {
enabled: false
},
media: {
enabled: false
},
recrawl: false,
structuredContent: {
title: {
type: "string",
selector: "article h1"
},
body: {
type: "string",
selector: "article div[data-gu-name='body']"
}
}
},
{ // Sky News home page - find links to articles
pattern: /^https?\:\/\/news\.sky\.com\/?$/i,
linkDiscovery: {
enabled: true,
crawlDiscovered: true,
internalOnly: true,
pattern: /^https?\:\/\/news\.sky\.com\/story\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\d+$/i
},
media: {
enabled: false
},
recrawl: true
},
{ // Sky News article pages
pattern: /^https?\:\/\/news\.sky\.com\/story\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\d+$/i,
linkDiscovery: {
enabled: false
},
media: {
enabled: false
},
recrawl: false,
structuredContent: {
title: {
type: "string",
selector: ".sdc-article-header__title"
},
body: {
type: "string",
selector: ".sdc-article-body"
}
}
},
{ // Politico home page - find links to articles
pattern: /^https?\:\/\/www\.politico\.eu\/?(\?no-geo-redirect)?$/i,
linkDiscovery: {
enabled: true,
crawlDiscovered: true,
internalOnly: true,
pattern: /^https?\:\/\/www\.politico\.eu\/(article|news)\/([A-Z][a-z0-9]*)(-[a-z0-9]+)*\/?$/i
},
media: {
enabled: false
},
recrawl: true
},
{ // Politico article pages
pattern: /^https?\:\/\/www\.politico\.eu\/article\/([A-Z][a-z0-9]*)(-[a-z0-9]+)*\/?$/i,
linkDiscovery: {
enabled: false
},
media: {
enabled: false
},
recrawl: false,
structuredContent: {
title: {
type: "string",
selector: "h1.article-meta__title"
},
body: {
type: "string",
selector: ".article__content"
}
}
},
{ // AP home page - find links to articles
pattern: /^https?\:\/\/apnews\.com\/?$/i,
linkDiscovery: {
enabled: true,
crawlDiscovered: true,
internalOnly: true,
pattern: /^https?\:\/\/apnews\.com\/article\/([a-z][a-z0-9]*)(-[a-z0-9]+)*$/i
},
media: {
enabled: false
},
recrawl: true
},
{ // AP articles
pattern: /^https?\:\/\/apnews\.com\/article\/([a-z][a-z0-9]*)(-[a-z0-9]+)*$/i,
linkDiscovery: {
enabled: false
},
media: {
enabled: false
},
recrawl: false,
structuredContent: {
title: {
type: "string",
selector: ".Body .Content h1"
},
body: {
type: "string",
selector: ".Body .Content .Article"
}
}
},
{ // DW home page - find links to articles
pattern: /^https?\:\/\/www\.dw\.com\/en\/?(top-stories.*)?$/i,
linkDiscovery: {
enabled: true,
crawlDiscovered: true,
internalOnly: true,
pattern: /^https?\:\/\/www\.dw\.com\/en\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\/a-\d+\/?$/i
},
media: {
enabled: false
},
recrawl: true
},
{ // DW articles
pattern: /^https?\:\/\/www\.dw\.com\/en\/([a-z][a-z0-9]*)(-[a-z0-9]+)*\/a-\d+\/?$/i,
linkDiscovery: {
enabled: false
},
media: {
enabled: false
},
recrawl: false,
structuredContent: {
title: {
type: "string",
selector: "body article:first-child h1"
},
body: {
type: "string",
selector: "body article:first-child"
}
}
}
],
config: {
maxParallelRequests: 5,
throttle: { // allows max 100 requests, max 5 per baseURL over a rolling 60 second window
maxRequests: 50, // should be more than maxParallelRequests
perBaseURL: 5,
time: 60 * 1000 // * 1000 for milliseconds
},
historyLength: 50, // number of requests to keep in the history
recrawlInterval: 15 * 60 * 1000, // 15 mins
followRedirects: true,
internalRedirectsOnly: true, // only allow internal redirects (within the same domain)
checkDatabase: true // Check if each item has already been crawled and saved in the db before crawling it. If it has, skip it.
}
};