-
Notifications
You must be signed in to change notification settings - Fork 0
/
Allmatch.js
35 lines (32 loc) · 1.09 KB
/
Allmatch.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
const request = require("request");
const cheerio = require("cheerio");
const scoreCardObj = require("./scorecard");
function getAllMatchesLink(url) {
request(url, function (err, response, html) {
if (err) {
console.log(err);
}
else {
extractAllLinks(html);
}
})
}
function extractAllLinks(html) {
// Laoding html to parse in $(selector)
// If the seslector is unquie match => returns that elem
// else returns array
let $ = cheerio.load(html);
// cheerio wraps the accessed index/attribute value
let scorecardElems = $("a[data-hover='Scorecard']");
// Parsing through all the values of returned array
for (let i = 0; i < scorecardElems.length; i++) {
let link = $(scorecardElems[i]).attr("href");
let fullLink = "https://www.espncricinfo.com" + link;
// console.log(fullLink);
scoreCardObj.ps(fullLink); // ps is function in scorecard.js
}
}
// Exporting the getAllMatchesLink function
module.exports = {
gAlmatches: getAllMatchesLink
}