关于node.js:爬虫spider

48次阅读

共计 528 个字符,预计需要花费 2 分钟才能阅读完成。

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);
        }
    })
}

正文完
 0