标签:world cti news 抓取 let als cat tle UNC
"use strict"; let cheerio = require("cheerio"); let http = require("http"); let iconv = require("iconv-lite"); let mainUrl = "http://news.sina.com.cn/world/"; http.get(mainUrl, function(sres) { var chunks = []; sres.on(‘data‘, function(chunk) { chunks.push(chunk); }); sres.on(‘end‘, function() { var html = iconv.decode(Buffer.concat(chunks), ‘utf8‘); var $ = cheerio.load(html, {decodeEntities: false}); $(‘.content a‘).each(function (idx,element){ let ele = $(element); let title = ele.text(); title = !!title?title.trim():‘‘; let url = ele.attr(‘href‘); url = !!url?url.trim():‘‘; if(title.length>4 && url.length>0&&url.indexOf(‘javascript‘)===-1){ console.log(title+‘|‘+url); } }) }); });
标签:world cti news 抓取 let als cat tle UNC
原文地址:https://www.cnblogs.com/sheryee/p/8783446.html