-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallMatches.js
More file actions
45 lines (42 loc) · 1.46 KB
/
allMatches.js
File metadata and controls
45 lines (42 loc) · 1.46 KB
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
// / Q1 print the result
// npm i request jsdom
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;
// pass to newJSDOM
let dom = new JSDOM(body);
// 2. // no meaning
// document represent the whole html page
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
}