美文网首页
Node爬虫

Node爬虫

作者: play_0 | 来源:发表于2017-08-31 10:31 被阅读0次
  • 使用cheerio爬虫模块
    抓取页面后获取元素信息跟jQuery基本一样
const cheerio = require('cheerio');
const co = require('co');

/**
 * @method 提取起点此资源信息
 * @param id 小说id(从列表页爬取到的)
 * @returns {Function}
 */
seachInfo(id) {
    return function (cb) {
        co(function* () {
            let result = yield Util.req.sendReq('http://book.qidian.com/info/' + id, 'GET', '', 'crawler');// 发送请求的工具类
            let $ = cheerio.load(result, {decodeEntities: false}); //采用cheerio模块解析html
            let novels = {};
            novels.img = $(".book-information .book-img img").attr('src');
            novels.name = $(".book-information .book-info h1 em").html();
            novels.author = $(".book-information .book-info .writer").html();
            let wordsNum = $(".book-information .book-info p em").eq(0).html();
            novels.wordsNum = parseInt(wordsNum) * 10000;
            novels.summary = $('.book-intro p').text();
            cb(null, novels);
        }).catch(function (err) {
            cb(new Error(err.message), null);
        })
    }
}

相关文章

  • node爬虫之路(一)

    最近对爬虫很感兴趣,我们node.js也是可以写爬虫。所以写一个node爬虫系列,记录我的爬虫之路,感兴趣的同学可...

  • node爬虫快速入门

    node爬虫 初入前端,刚刚接触node,对于耳闻已久的node爬虫非常神往,所以有了这篇文章,项目代码在文章末尾...

  • node入门场景之——爬虫

    边做边学效率更高,爬虫是node的适用场景之一,关于爬虫的另一篇文章node爬虫进阶之——登录为了验证“经验总结、...

  • node 爬虫

    clawer.js

  • node爬虫

    node爬虫用到的第三方模块 Cheerio 服务端的jQueryhttps://segmentfault.c...

  • Node爬虫

    使用cheerio爬虫模块抓取页面后获取元素信息跟jQuery基本一样

  • node爬虫

    /** 教程:https://blog.csdn.net/Qc1998/article/details/83154...

  • node 爬虫

  • node爬虫

    声明:所有文章都是转载整理的,只是为了自己学习,方便自己观看,如有侵权,请立即联系我,谢谢~ Node.js的学习...

  • node爬虫

    以下代码爬取豆瓣电影网的数据并且写入数据库首先安装cheerio和mysql

网友评论

      本文标题:Node爬虫

      本文链接:https://www.haomeiwen.com/subject/aszfjxtx.html