首页 > 其他 > 详细

superagent和request结果转换区别

时间:2017-04-28 15:20:28      阅读:1252      评论:0      收藏:0      [点我收藏+]

superagent和request结果转换区别

使用superagent和request抓取页面内容时,两个抓取内容都可以被cheerio进行处理。但处理时有个细微差别。

1. 使用superagent

request(url, function(err, response, html){
if(!err){
var $ = cheerio.load(html.toString());
//your code here
}
}

2. 使用request

superagent.get(Url).end(function(err,html){
if(!error){
var $ = cheerio.load(html.text);
//your code here
}
}

两者的区别在于对抓取的结果获取内容的方式不同。一个是html.toString(),一个是html.text。

The res.text property contains the unparsed response body string(res.text是superagent的属性)

superagent和request结果转换区别

原文:http://www.cnblogs.com/sylarmeng/p/6781453.html

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