-
Notifications
You must be signed in to change notification settings - Fork 0
/
allmatchPage.js
38 lines (37 loc) · 1.32 KB
/
allmatchPage.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
const request = require('request');
const fs = require("fs");
const jsdom = require("jsdom");
const scoreCardObj = require("./scorecard");
function AllMatchPageExecutor(url) {
request(url, cb);
}
function cb(error, response, body) {
if (error) {
console.log('error:', error.message); // Print the error message
} else if (response && response.statusCode == 404) {
console.log("Page not found");
} else {
console.log("content recieved");
// console.log(body);
extractData(body);
}
}
function extractData(body) {
const JSDOM = jsdom.JSDOM;
let dom = new JSDOM(body);
let document = dom.window.document;
let matchBoxes = document.querySelectorAll(".ds-flex.ds-mx-4.ds-pt-2.ds-pb-3.ds-space-x-4.ds-border-t.ds-border-line-default-translucent")
for (let i = 0; i < matchBoxes.length; i++) {
let curMatch = matchBoxes[i];
let allAnchors = curMatch.querySelectorAll("a");
let scoreCardAnchor = allAnchors[2];
let link = scoreCardAnchor.getAttribute("href");
let scoreCardLink = "https://www.espncricinfo.com" + link;
console.log(scoreCardLink);
scoreCardObj.scoreCardFn(scoreCardLink);
}
console.log("```````````````````````````````````````````````");
}
module.exports = {
AllmatchFn: AllMatchPageExecutor
}