-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
38 lines (33 loc) · 1.05 KB
/
main.js
File metadata and controls
38 lines (33 loc) · 1.05 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
//homepage / topic
let url = "https://github.com/topics";
const request = require('request')
const cheerio = require('cheerio')
const getreposLink = require('./reposPage')
request(url,function(err,response,html){
if(err){
console.log("Error");
}
else{
// console.log(html);
gettopicLinks(html);
}
})
//css selector & cheerio -> reading html
function gettopicLinks(html){
//read htlm->cheerio
let $ = cheerio.load(html);
let topicEleArr = $(".no-underline.d-flex.flex-column.flex-justify-center");
let topicName = $(".f3.lh-condensed.text-center.Link--primary.mb-0.mt-1");
//3 topics
for(let i = 0;i < topicEleArr.length;i++){
let href = $(topicEleArr[i]).attr("href");
// console.log(href);
let topic = href.split("/").pop();
let fulllink = `https://github.com${href}`;
// console.log(topic);
// console.log(fulllink);
getreposLink(fulllink,topic);
// console.log(`----------------`);
}
// console.log(topicName.text());
}