-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
38 lines (35 loc) · 1.26 KB
/
home.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
const request = require('request');
const fs = require("fs");
const path = require("path");
const jsdom = require("jsdom");
const allMatchPageObj = require("./allMatchPage");
const helperObj = require("./helper");
let url = "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423";
let iplPath = path.join(__dirname, "ipl");
helperObj.dirCreater(iplPath);
// first request
request(url, cb);
function cb(error, response, body) {
if (error) {
console.log('error:', 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;
let dom = new JSDOM(body);
// document represent the whole html page
let document = dom.window.document;
let element = document.querySelector(".ds-block.ds-text-center.ds-uppercase.ds-text-ui-typo-primary.ds-underline-offset-4")
let link = element.getAttribute("href");
// console.log("link", link);
let AllMatchPageKaLink = "https://www.espncricinfo.com" + link;
console.log(AllMatchPageKaLink);
// allmatch page
allMatchPageObj.AllmatchFn(AllMatchPageKaLink)
}