标签:nodejs ext text UNC require style col sum lse
const 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‘); } });
标签:nodejs ext text UNC require style col sum lse
原文地址:https://www.cnblogs.com/qiuxd/p/13168194.html