爬虫spider
作者:互联网
转:
爬虫spider
const originRequest = require('request');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const request = (url, cb ) => {
const options = {
url: url,
encoding: null
};
originRequest(url, options, cb);
}
for (let i=1; i< 10; i++) {
const url = `https://www.gdnync.com/news/snzx/list_1_${i}.html`;
request(url, (err, res, body) => {
const html = iconv.decode(body, 'gb2312');
const $ = cheerio.load(html);
const list = $('.list-group-item');
for (let i=0,len=list.length; i<len; i++)="" {="" let="" title="list.eq(i).find('.nc-subcolumn-list-item-title').text();" console.log(title);="" }="" })="" <="" code="">
标签:iconv,const,url,cheerio,list,spider,爬虫,html 来源: https://www.cnblogs.com/wangtcc/p/14743439.html