-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreCard.js
More file actions
54 lines (51 loc) · 1.93 KB
/
scoreCard.js
File metadata and controls
54 lines (51 loc) · 1.93 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
46
47
48
49
50
51
52
53
54
// let url = "https://www.espncricinfo.com/series/ipl-2020-21-1210595/mumbai-indians-vs-chennai-super-kings-1st-match-1216492/full-scorecard";
let request = require("request");
let cheerio = require("cheerio");
let fs = require("fs");
function processSinglematch(url) {
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)
// team name
let bothInningArr = searchTool(".Collapsible");
for (let i = 0; i < bothInningArr.length; i++) {
// scoreCard = searchTool(bothInningArr[i]).html();
let teamNameElem = searchTool(bothInningArr[i]).find("h5");
let teamName = teamNameElem.text();
// console.log(teamName);
teamName = teamName.split("INNINGS")[0];
// console.log(teamName);
teamName = teamName.trim();
console.log(teamName);
let batsManTableBodyAllRows = searchTool(bothInningArr[i]).find(".table.batsman tbody tr");
console.log(batsManTableBodyAllRows.length)
// type cohersion loops ->
for (let j = 0; j < batsManTableBodyAllRows.length; j++) {
let numberofTds = searchTool(batsManTableBodyAllRows[j]).find("td");
// console.log(numberofTds.length);
if (numberofTds.length == 8) {
// console.log("You are valid")
let playerName = searchTool(numberofTds[0]).text();
console.log(playerName);
}
}
console.log("``````````````````````````````````````")
// fs.writeFileSync(`innning${i+1}.html`,scoreCard);
}
// players name
}
module.exports = {
processSinglematch
}