-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallmatch.js
More file actions
46 lines (44 loc) · 1.29 KB
/
allmatch.js
File metadata and controls
46 lines (44 loc) · 1.29 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
// request module-> npm -> install
let req = require("request");
// cheerio -> pass html -> read -> parse-> tool
let ch = require("cheerio");
let obj = require("./main.js");
const { processMatch } = require("./main.js");
// io -> xlsx
// npm
// to do crud
// program bottleNeck
// expose -> async function
console.log("Before");
// request -> to make request to server -> and get html file
// let url = 'https://www.espncricinfo.com/series/ipl-2020-21-1210595/match-results';
function getScoreCardUrl(url) {
req(url, cb);
}
function cb(error, response, data) {
// resoure not found
if (response.statusCode == 404) {
console.log("Page not found");
// resource found
} else if (response.statusCode == 200) {
// console.log(data);
parseHTML(data);
} else {
console.log(err);
}
}
function parseHTML(data) {
let fTool = ch.load(data);
let AllScorecardElem = fTool('.match-info-link-FIXTURES');
for (let i = 0; i < AllScorecardElem.length; i++) {
let url = ch(AllScorecardElem[i]).attr("href");
let fullUrl = "https://www.espncricinfo.com" + url;
obj.pm(fullUrl);
}
// console.log(AllScorecardElem.length);
}
console.log("After");
console.log("Req send");
module.exports = {
getScoreCardUrl: getScoreCardUrl
}