nodejs 爬热搜
2021-02-02 20:14
标签:nodejs ext text UNC require style col sum lse nodejs 爬热搜 标签:nodejs ext text UNC require style col sum lse 原文地址:https://www.cnblogs.com/qiuxd/p/13168194.htmlconst request = require(‘request‘);
const cheerio = require(‘cheerio‘);
const fs = require(‘fs‘);
const url = ‘https://s.weibo.com/top/summary‘;
request(url, (err, resp, body) => {
if (err) {
console.log(err);
} else {
const $ = cheerio.load(body);
const news = [];
$(".td-02 a").each(function(i, elem) {
let newItem = {
text: $(this).text(),
url: $(this).attr(‘href‘)
};
news[i] = newItem;
});
fs.writeFile(‘output.json‘, JSON.stringify(news), function (err) {
if (err) {
console.log(err);
} else {
console.log(‘ok.‘);
}
});
console.log(‘end‘);
}
});
下一篇:thinkphp queue队列