-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
53 lines (51 loc) · 1.83 KB
/
main.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
let url = "https://www.espncricinfo.com/series/ipl-2020-21-1210595";
let request = require("request");
let cheerio = require("cheerio");
let scoreCardObj=require("./scoreCard")
// myTeamName name venue date opponentTeamName result runs balls fours sixes sr
request(url, cb);
function cb(error, response, html) {
if (error) {
console.log(error); // Print the error if one occurred
} else if (response.statusCode == 404) {
console.log("Page Not Found")
}
else {
// console.log(html); // Print the HTML for the request made
dataExtracter(html);
}
}
function dataExtracter(html) {
let searchTool = cheerio.load(html);
let anchorrep = searchTool('a[data-hover="View All Results"]');
let link = anchorrep.attr("href");
// console.log("link",link);
let fullAllmatchPageLink
= `https://www.espncricinfo.com${link}`;
console.log(fullAllmatchPageLink);
// go to all match Page
request(fullAllmatchPageLink, allMatchPageCb);
}
function allMatchPageCb(error, response, html) {
if (error) {
console.log(error); // Print the error if one occurred
} else if (response.statusCode == 404) {
console.log("Page Not Found")
}
else {
// console.log(html); // Print the HTML for the request made
getAllScoreCardLink(html);
}
}
function getAllScoreCardLink(html) {
console.log("```````````````````````");
let searchTool = cheerio.load(html);
let scorecardsArr = searchTool("a[data-hover='Scorecard']");
for (let i = 0; i < scorecardsArr.length; i++) {
let link = searchTool(scorecardsArr[i]).attr("href");
let fullAllmatchPageLink= `https://www.espncricinfo.com${link}`;
console.log(fullAllmatchPageLink);
scoreCardObj.processSinglematch(fullAllmatchPageLink)
}
console.log("`````````````````");
}