首页 > Web开发 > 详细

cheerio--不用正则表达式采集网页上的数据

时间:2015-12-27 15:55:25      阅读:344      评论:0      收藏:0      [点我收藏+]

理由:烦正则表达式。

蹊径:解析html为dom树,然后用javascript取回数据。
工具:cheeriojs——"服务端的jQuery"。
 
示例:
var cheerio = require(‘cheerio‘),
    $ = cheerio.load(‘<h2 class = "title">Hello world</h2>‘);

$(‘h2.title‘).text(‘Hello there!‘);
$(‘h2‘).addClass(‘welcome‘);

$.html();
//=> <h2 class = "title welcome">Hello there!</h2>
 
帮助:
        cheeriojs在npmjs
 
搭配推荐:
        superagent  _github.io / http
        request  _github.com / http

cheerio--不用正则表达式采集网页上的数据

原文:http://www.cnblogs.com/yasir/p/js_cheerio.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!