-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome.js
More file actions
45 lines (39 loc) · 1.41 KB
/
home.js
File metadata and controls
45 lines (39 loc) · 1.41 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
// Q1 print the result
// npm i request jsdom
const request = require('request');
const fs = require("fs");
const path = require("path");
const jsdom = require("jsdom");
const allMatchPageObj = require("./allMatches");
const helperObj = require("./helper");
let url = "https://www.espncricinfo.com/series/ipl-2021-1249214";
let iplPath = path.join(__dirname, "IPL");
helperObj.dirCreator(iplPath); //Nhi hoga toh bna dega hoga toh nhi bneyaga
// first request
request(url, cb);
function cb(error, response, body) {
if (error) {
console.log('error:', error.message); // Print the 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;
// pass to newJSDOM
let dom = new JSDOM(body);
// 2. // no meaning
// 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)
}