-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
40 lines (30 loc) · 917 Bytes
/
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
const request = require("request");
const cheerio = require("cheerio");
const fs = require("fs");
const path = require("path");
const { getAllMatches } = require("./getAllMatchLinks");
const url = "https://www.espncricinfo.com/series/ipl-2020-21-1210595";
let iplPath = path.join(__dirname, "IPL");
iplDir(iplPath);
request(url, cb);
function cb(error, response, html) {
if (error) {
console.log(error);
} else {
console.log(html);
// extractLink(html);
}
}
function extractLink(html) {
let $ = cheerio.load(html);
let anchorElm = $(".ds-border-t.ds-border-line.ds-text-center.ds-py-2 a");
let link = anchorElm.attr("href");
const fullLink = "https://www.espncricinfo.com/" + link;
// console.log(fullLink);
getAllMatches(fullLink);
}
function iplDir(iplPath) {
if (fs.existsSync(iplPath) == false) {
fs.mkdirSync(iplPath);
}
}