-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (27 loc) · 921 Bytes
/
server.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
const request = require("request");
const cheerio = require('cheerio');
const links = [] , titles = []
const data = []
const url = "https://time.com";
request(url, (err, res, body) => {
if (err) console.log(err)
else {
const $ = cheerio.load(body)
let title = $('section[class="homepage-module latest"] a').each((index, value) => {
var title = $(value).text();
titles.push({ "title": title });
});
let link = $('section[class="homepage-module latest"] a').each((index, value) => {
var link = $(value).attr('href');
links.push({ "link": url + link });
});
for (let i = 0; i < titles.length; i++) {
const dict = {}
dict.title = titles[i]['title']
dict.link = links[i]['link']
data.push(dict)
}
console.log(data);
}
})
module.exports = data;