-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scrapper1.js
694 lines (594 loc) · 28.1 KB
/
Scrapper1.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
const puppeteer = require('puppeteer');
const generateLatLongs = require("./generateLatLongs");
const helpers = require("./helperFunctions");
const timestamp = new Date().getTime();
const MAX_RETRY = 3;
var retry = 0;
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: `output_${timestamp}.csv`,
header: [
{ id: 'platform', title: 'platform' },
{ id: 'title', title: 'title' },
{ id: 'location', title: 'location' },
{ id: 'description', title: 'description' },
{ id: 'contactPhone', title: 'contactPhone' },
{ id: 'startDate', title: 'startDate' },
{ id: 'endDate', title: 'endDate' },
{ id: 'photoUrl', title: 'photoUrl' },
{ id: 'eventUrl', title: 'eventUrl' },
{ id: 'contactEmail', title: 'contactEmail' },
]
});
async function init() {
let results = [];
retry = 0;
let NorcalRes = await getDataFromNorcalcarculture();
results = results.concat(NorcalRes.result);
await NorcalRes.browser.close();
retry = 0;
let atodomotoRep = await processDataFromAtodomotor();
results = results.concat(atodomotoRep.result);
await atodomotoRep.browser.close();
retry = 0;
let SocalcarcultureResp = await processDataFromSocalcarculture();
results = results.concat(SocalcarcultureResp.result);
await SocalcarcultureResp.browser.close();
retry = 0;
let DuponRes = await getDataFromhttpsDupontregistry();
results = results.concat(DuponRes.result);
await DuponRes.browser.close();
retry = 0;
let thermotorRes = await processDataFromThemotoringdiary();
results = results.concat(thermotorRes.result);
await thermotorRes.browser.close();
console.log("Total " + results.length + " events pulled.");
csvWriter
.writeRecords(results)
.then(() => {
console.log('The CSV file was written successfully');
generateLatLongs({timestamp: timestamp});
});
}
init();
async function processDataFromAtodomotor() {
const browser = await puppeteer.launch({
headless: false,
networkIdleTimeout: 10000,
waitUntil: 'networkidle0',
args: ['--start-maximized', '--window-size=1366,700']
});
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 700 });
return await getDataFromAtodomotor(page, browser, []);
}
async function processDataFromSocalcarculture() {
const browser = await puppeteer.launch({
headless: false,
networkIdleTimeout: 10000,
waitUntil: 'networkidle0',
args: ['--start-maximized', '--window-size=1366,700']
});
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 700 });
return await getDataFromSocalCarCulture(page, browser, []);
}
async function processDataFromThemotoringdiary() {
const browser = await puppeteer.launch({
headless: false,
networkIdleTimeout: 10000,
waitUntil: 'networkidle0',
args: ['--start-maximized', '--window-size=1366,700']
});
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 700 });
await page.setRequestInterception(true);
page.on('request', (req) => {
if(req.resourceType() == 'stylesheet' || req.resourceType() == 'font' || req.resourceType() == 'image'){
req.abort();
}
else {
req.continue();
}
});
return await getDataFromThemotoringdiary(page, browser, []);
}
async function getDataFromNorcalcarculture() {
const browser = await puppeteer.launch({
headless: false,
networkIdleTimeout: 10000,
waitUntil: 'networkidle0',
args: ['--start-maximized', '--window-size=1366,700']
});
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 700 });
let results = [];
try {
await page.goto('https://norcalcarculture.com/', {waitUntil: 'load'});
console.log("Started to fetch data from https://norcalcarculture.com ");
results = await page.evaluate(() => {
let results = [];
let events = document.querySelectorAll('.entry-content p');
for (var i = 0; i < events.length; i++) {
if (!(events[i] && events[i].querySelector("a > strong"))) {
continue;
}
let title = "", startDate = "", endDate = "", location = "";
let eventText = events[i].innerText;
// get title
title = (events[i].querySelector("a > strong")).innerText;
// get date
// note: year is hardcoded as current year
let date = "";
if (eventText.indexOf("is") !== -1) {
date = eventText.substring(eventText.indexOf("is") + 3, eventText.lastIndexOf(" at"));
} else {
date = eventText.substring(eventText.indexOf("are") + 4, eventText.lastIndexOf(" at"));
}
date = date.substring(date.indexOf(",")).trim();
let startEndDates = date.match(/(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?) [0-9]{1,2}(th|nd|rd|st)?/ig);
let startEndTimes = date.match(/[0-9]{1,2}(:?[0-9]{1,2})?(am|pm)/ig);
let currentYear = (new Date).getFullYear();
// parse start date
if (startEndDates && startEndDates[0]) {
startDate = startEndDates[0] + " " + currentYear;
if (startEndTimes && startEndTimes[0]) {
startDate = startDate + " " + startEndTimes[0];
}
}
// parse end date
if (startEndDates && startEndDates[0] && startEndDates[1]) {
endDate = startEndDates[1] + " " + currentYear;
} else if (startEndDates && startEndDates[0]) {
endDate = startEndDates[0] + " " + currentYear;
}
if (startEndTimes && startEndTimes[1]) {
endDate = endDate + " " + startEndTimes[1];
}
// get location
if (eventText.includes(" at ")) {
location = eventText.substring(eventText.lastIndexOf(" at ") + 4);
} else if (eventText.includes(" on ")) {
location = eventText.substring(eventText.lastIndexOf(" on ") + 4);
}
results.push({
"platform": "https://norcalcarculture.com/",
"startDate": startDate,
"endDate": endDate,
"title": title,
"description": "",
"location": location,
"contactPhone": "",
"photoUrl": "",
"eventUrl": "",
"contactEmail": "",
});
}
return results;
});
} catch (error) {
console.log(error);
if (error.name === "TimeoutError" && ++retry <= MAX_RETRY) {
browser.close();
console.log("Timeout error retrying....")
retryResponse = (await getDataFromNorcalcarculture());
results = retryResponse.result;
retryResponse.browser.close();
}
browser.close();
}
console.log(results);
console.log("pulled " + results.length + " events");
return {
'result': results,
'browser': browser
}
}
async function getDataFromAtodomotor(page, browser, results) {
try {
await page.goto('https://www.atodomotor.com/agenda/2019');
let eventBox = await page.$$('.listBox');
for (var i = 0; i < eventBox.length; i++) {
let startDate = "", endDate = "", title = "";
// get title
let titleEl = await page.$$('.listBoxContent div[itemprop="name"]');
if (titleEl && titleEl[i]) {
title = await (await titleEl[i].getProperty('innerText')).jsonValue();
}
// get start and end date
let fullDateEl = await page.$$('.listBoxContent .listBoxSubtitle');
if (fullDateEl && fullDateEl[i]) {
let fullDateText = await (await fullDateEl[i].getProperty('innerText')).jsonValue();
// convert month to english language
let spanishMonthMatch = fullDateText.match(/\b(Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Septiembre|Octubre|Noviembre|Diciembre)\b/ig);
if (spanishMonthMatch && spanishMonthMatch[0]) {
let englishMonth = helpers.convertMonthFromSpanishToEnglish(spanishMonthMatch[0]);
fullDateText = fullDateText.replace(spanishMonthMatch[0], englishMonth);
}
let monthMatch = fullDateText.match(/\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)\b/ig);
let yearMatch = fullDateText.match(/\b[0-9]{4}\b/g);
let datesMatch = fullDateText.match(/\b[0-9]{1,2}\b/g);
if (datesMatch && datesMatch[0]) {
startDate = datesMatch[0];
if (monthMatch && monthMatch[0]) {
startDate += " " + monthMatch[0];
}
if (yearMatch && yearMatch[0]) {
startDate += " " + yearMatch[0];
}
if (datesMatch[1]) {
endDate = datesMatch[1];
if (monthMatch && monthMatch[0]) {
endDate += " " + monthMatch[0];
}
if (yearMatch && yearMatch[0]) {
endDate += " " + yearMatch[0];
}
}
}
}
results.push({
"platform": "https://www.atodomotor.com/agenda/2019",
"title": title,
"description": "",
"location": "",
"contactPhone": "",
"startDate": startDate,
"endDate": endDate,
"photoUrl": "",
"eventUrl": "",
"contactEmail": "",
});
}
} catch (error) {
console.log(error);
if (error.name === "TimeoutError" && ++retry <= MAX_RETRY) {
browser.close();
console.log("Timeout error retrying....")
retryResponse = (await processDataFromAtodomotor());
results = retryResponse.result;
retryResponse.browser.close();
}
browser.close();
}
console.log("results .... ", results);
console.log("pulled ", results.length, " results");
return {
'result': results,
'browser': browser
}
}
async function getDataFromSocalCarCulture(page, browser, results) {
try {
await page.goto('http://www.socalcarculture.com/events.html');
results = await page.evaluate(() => {
let results = [];
let trEl = document.querySelectorAll('#Layer3 table tbody tr');
let yearImgEl = trEl[2].querySelector("tr td > img");
let year = yearImgEl.getAttribute("src").match(/[0-9]{4}/g)[0];
for (let i = 3; i < trEl.length; i++) {
// while trEl contains month image
while (trEl[i] && trEl[i].querySelector("tr > td > img")) {
yearImgEl = trEl[i].querySelector("tr td > img");
yearEl = yearImgEl.getAttribute("src").match(/[0-9]{4}/g);
// if next year
if (yearEl && yearEl[0]) {
year = yearEl[0]
i++;
}
const monthImgEl = trEl[i].querySelector("tr td > img");
let month = monthImgEl.getAttribute("src").match(/(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)/ig)[0];
i++;
// skip non event trEl
if (trEl[i] && !trEl[i].querySelector("tr > td > b")) {
while (trEl[i] && !trEl[i].querySelector("tr > td > b")) {
i++;
}
}
// while trEl contains event
while (trEl[i] && trEl[i].querySelector("tr > td > b")) {
let startDate = "", endDate = "", title = "", location = "";
const event = trEl[i];
// console.log(event);
let eventText = event.querySelector(":nth-child(2)").innerText;
// console.log(eventText);
// get start and end date
let datesText = event.querySelector(":nth-child(1) td").innerText;
let datesMatch = datesText.match(/[0-9]{1,2}/g);
let timesMatch = eventText.match(/\b([0-9]{1,2})(:?[0-9]{1,2})?\s?(a.?m.?|p.?m.?)\b/ig);
if (datesMatch && datesMatch[0]) {
startDate = datesMatch[0] + " " + month + " " + year;
if (timesMatch && timesMatch[0]) {
startDate += " " + timesMatch[0];
}
if (datesMatch[1]) {
endDate = datesMatch[1] + " " + month + " " + year;
if (timesMatch && timesMatch[1]) {
endDate += " " + timesMatch[1];
}
} else {
endDate = datesMatch[0] + " " + month + " " + year;
if (timesMatch && timesMatch[1]) {
endDate += " " + timesMatch[1];
}
}
}
let place = eventText.substring(0, eventText.indexOf(" - "));
place = place.replace("*", "");
eventText = eventText.substring(eventText.indexOf(" - ") + 2); // remove venue from eventText
let address = "";
if (eventText.includes(" @ ")) {
title = eventText.substring(0, eventText.indexOf(" @ ")).trim();
eventText = eventText.substring(eventText.indexOf(" @ ") + 2); // remove title from eventText
address = eventText.substring(0, eventText.indexOf(" - ")).trim();
} else {
title = eventText.substring(0, eventText.indexOf(" - ")).trim();
eventText = eventText.substring(eventText.indexOf(" - ") + 2); // remove title from eventText
address = eventText.substring(0, eventText.indexOf(" - ")).trim();
}
location = address + ", " + place;
results.push({
"platform": "http://www.socalcarculture.com/events.html",
"title": title,
"location": location,
"description": "",
"contactPhone": "",
"startDate": startDate,
"endDate": endDate,
"photoUrl": "",
"eventUrl": "",
"contactEmail": "",
});
i++;
}
}
}
return results;
});
} catch (error) {
console.log(error);
if (error.name === "TimeoutError" && ++retry <= MAX_RETRY) {
browser.close();
console.log("Timeout error retrying....")
retryResponse = (await processDataFromSocalcarculture());
results = retryResponse.result;
retryResponse.browser.close();
}
browser.close();
}
console.log(results);
console.log("pulled " + results.length + " events");
return {
'result': results,
'browser': browser
}
}
async function getDataFromhttpsDupontregistry() {
const browser = await puppeteer.launch({
headless: false,
networkIdleTimeout: 10000,
waitUntil: 'networkidle0',
args: ['--start-maximized', '--window-size=1366,700']
});
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 700 });
let results = []
try {
await page.goto('https://directory.dupontregistry.com/explore/?type=event&sort=upcoming', { waitUntil: 'domcontentloaded' });
console.log("Started to fetch data from directory.dupontregistry.com ");
var currentPage = 1;
await page.waitForSelector('.job-manager-pagination ul li');
var pagesCount = (await page.$$(".job-manager-pagination ul li")).length - 1;
do {
let urls = await page.evaluate(() => {
let newUrls = [];
let items = document.querySelectorAll('.results-view .grid-item .lf-item-container .lf-item.lf-item-alternate > a');
items.forEach((item) => {
newUrls.push(item.getAttribute('href'));
});
return newUrls;
});
for (let i = 0; i < urls.length; i++) {
await page.goto(urls[i], { waitUntil: 'domcontentloaded' });
await new Promise(resolve => setTimeout(resolve, 2000));
let startDate = "", endDate = "", title = "", description = "";
let address = "", contactPhone = "", contactEmail = "", photoUrl = "";
// get title
let titleEl = await page.$$('.profile-name .case27-primary-text');
if (titleEl && titleEl[0]) {
title = await (await titleEl[0].getProperty('innerText')).jsonValue();
}
// get description
let descriptionEl = await page.$$('.row.cts-column-wrapper.cts-main-column .element.content-block.wp-editor-content .pf-body');
if (descriptionEl && descriptionEl[0]) {
description = await (await descriptionEl[0].getProperty('innerText')).jsonValue();
}
// get event start and end date
let fullStartDateEl = await page.$$('.price-or-date .value');
let year = "";
if (fullStartDateEl && fullStartDateEl[0]) {
let fullStartDateText = await (await fullStartDateEl[0].getProperty('innerText')).jsonValue();
year = fullStartDateText.substr(-4);
}
let dateEl = await page.$$('.row.cts-column-wrapper.cts-side-column .element.content-block .pf-body');
if (dateEl && dateEl[0]) {
let dateText = await (await dateEl[0].getProperty('innerText')).jsonValue();
dateText = dateText.replace(/at/g, year);
startDate = dateText.replace(/\n/g, " ").substr(dateText.indexOf("Event Start"), dateText.indexOf("Event End"));
startDate = startDate.replace("Event Start ", "").trim();
endDate = dateText.replace(/\n/g, " ").substr(dateText.indexOf("Event End"), dateText.length);
endDate = endDate.replace("Event End ", "").trim();
}
// get address
let addressEl = await page.$$('.block-field-job_location .pf-body > p:nth-child(2)');
if (addressEl && addressEl[0]) {
address = await (await addressEl[0].getProperty('innerText')).jsonValue();
}
// get contactPhone
let contactPhoneEl = await page.$$('.block-field-job_phone .pf-body:nth-child(2)');
if (contactPhoneEl && contactPhoneEl[0]) {
contactPhone = await (await contactPhoneEl[0].getProperty('innerText')).jsonValue();
}
// get contactEmail
contactEmail = await page.evaluate(() => {
let contactEmailChildEl = document.querySelector('.icon-email-outbox');
if (contactEmailChildEl) {
let email = contactEmailChildEl.parentNode.getAttribute("href");
email = email.replace("mailto:", "");
} else {
return "";
}
});
// get photo url
let photoUrlText = await page.evaluate(() => {
let photoEl = document.querySelector('.profile-cover.parallax-bg.profile-cover-image');
if (photoEl) {
return photoEl.getAttribute("data-jarallax-original-styles");
} else {
return "";
}
});
if (photoUrlText) {
photoUrl = photoUrlText.replace("background-image: url('", "").replace("');", "");
}
results.push({
"platform": "https://directory.dupontregistry.com/explore/?type=event&sort=upcoming",
"title": title,
"location": address,
"description": description,
"contactPhone": contactPhone,
"startDate": startDate,
"endDate": endDate,
"photoUrl": photoUrl,
"eventUrl": urls[i],
"contactEmail": contactEmail,
})
}
currentPage++;
await page.goto(`https://directory.dupontregistry.com/explore/?type=event&sort=upcoming&pg=${currentPage}`);
await new Promise(resolve => setTimeout(resolve, 2000));
} while (currentPage <= pagesCount);
} catch (error) {
console.log(error);
if (error.name === "TimeoutError" && ++retry <= MAX_RETRY) {
browser.close();
console.log("Timeout error retrying....")
retryResponse = (await getDataFromhttpsDupontregistry());
results = retryResponse.result;
retryResponse.browser.close();
}
browser.close();
}
console.log(results);
console.log("pulled ", results.length, " events");
return {
'result': results,
'browser': browser
}
}
async function getDataFromThemotoringdiary(page, browser, results) {
try {
await page.goto('https://www.themotoringdiary.com/');
console.log("pulling data for https://www.themotoringdiary.com/");
var currentPage = 1;
let events = (await page.$$("#tribe-events .tribe-events-loop .type-tribe_events"));
// loop while we have events
while (events.length) {
// get all events urls from current page
let urls = await page.evaluate(() => {
let newUrls = [];
let items = document.querySelectorAll('#tribe-events .tribe-events-loop .type-tribe_events a.tribe-event-url');
items.forEach((item) => {
newUrls.push(item.getAttribute('href'));
});
return newUrls;
});
// visit each page and extract information
for (let i = 0; i < urls.length; i++) {
await page.goto(urls[i], { waitUntil: 'domcontentloaded' });
await new Promise(resolve => setTimeout(resolve, 2000));
let startDate = "", endDate = "", title = "", description = "";
let location = "", contactPhone = "", contactEmail = ""; photoUrl = "";
// get title
let titleEl = await page.$$('#tribe-events .tribe-events-single-event-title');
if (titleEl && titleEl[0]) {
title = await (await titleEl[0].getProperty('innerText')).jsonValue();
}
// get description
let descriptionEl = await page.$$('#tribe-events .tribe-events-single-event-description p');
if (descriptionEl && descriptionEl[0]) {
description = await (await descriptionEl[0].getProperty('innerText')).jsonValue();
}
// get event start and end date
let fullDateEl = await page.$$('#tribe-events .tribe-events-schedule');
if (fullDateEl && fullDateEl[0]) {
let fullDateText = await (await fullDateEl[0].getProperty('innerText')).jsonValue();
[startDate, endDate] = helpers.getStartAndEndDates(fullDateText);
}
// get location
let venueEl = await page.$$('#tribe-events .tribe-venue');
let addressEl = await page.$$('#tribe-events .tribe-address');
let venue = "", address = "";
if (venueEl && venueEl[0]) {
venue = await (await venueEl[0].getProperty('innerText')).jsonValue();
}
if (addressEl && addressEl[0]) {
address = await (await addressEl[0].getProperty('innerText')).jsonValue();
}
location = venue + "\n" + address;
// get contact phone
let contactPhoneEl = await page.$$('#tribe-events .tribe-events-single-section .tribe-venue-tel');
if (contactPhoneEl && contactPhoneEl[0]) {
contactPhone = await (await contactPhoneEl[0].getProperty('innerText')).jsonValue();
}
// get contact email
let contactEmailEl = await page.$$('#tribe-events .tribe-events-single-section .tribe-organizer-email');
if (contactEmailEl && contactEmailEl[0]) {
contactEmail = await (await contactEmailEl[0].getProperty('innerText')).jsonValue();
}
// get photoUrl
photoUrl = await page.evaluate(() => {
let photoEl = document.querySelector('#tribe-events .tribe-events-event-image img');
if (photoEl) {
return photoEl.getAttribute("src");
} else {
return "";
}
});
results.push({
"platform": "https://www.themotoringdiary.com",
"title": title,
"location": location,
"description": description,
"contactPhone": contactPhone,
"startDate": startDate,
"endDate": endDate,
"photoUrl": photoUrl,
"eventUrl": urls[i],
"contactEmail": contactEmail,
})
}
// go to next page
currentPage++;
await page.goto(`https://www.themotoringdiary.com/?tribe_paged=${currentPage}`);
await new Promise(resolve => setTimeout(resolve, 2000));
events = (await page.$$("#tribe-events .tribe-events-loop .type-tribe_events"));
};
} catch (error) {
console.log(error);
if (error.name === "TimeoutError" && ++retry <= MAX_RETRY) {
browser.close();
console.log("Timeout error retrying....")
retryResponse = (await processDataFromThemotoringdiary());
results = retryResponse.result;
retryResponse.browser.close();
}
browser.close();
}
console.log(results);
console.log("pulled " + results.length + " events");
return {
'result': results,
'browser': browser
}
}