node.js 学习笔记003 :使用superagent和cheerio实现简单网页爬虫
来源:互联网 发布:独立游戏开发者 知乎 编辑:程序博客网 时间:2024/05/16 14:26
superagent
能够实现主动发起get/post/delete等请求
cheerio
则能够对请求结果进行解析,解析方式和jquery的解析方式几乎完全相同
superagent
网址:http://visionmedia.github.io/superagent/
cheerio
网址:https://github.com/cheeriojs/cheerio
1.安装superagent、cheerio
npm install superagent cheerio --save
2.功能实现
var express=require("express");var superagent=require("superagent");var cheerio=require("cheerio");var app=express();app.get("/",function(req,resp){ superagent.get("https://cnodejs.org/").end(function(error,data){ if(error){ console.log("error exception occured !"); return next(error); } var $=cheerio.load(data.text); //注意传递的是data.text而不是data本身 var arr=[]; $('#topic_list .topic_title').each(function(idx,element){ var $element=$(element); arr.push({ "title":$element.attr("title"), "href":$element.attr("href") }); }); resp.send(arr); });});app.listen(3000,function(req,resp){ console.log("server is running ......"); });
3.测试方法
http://localhost:3000
0 0
- node.js 学习笔记003 :使用superagent和cheerio实现简单网页爬虫
- 使用 superagent 与 cheerio 完成简单爬虫
- 使用 superagent 与 cheerio 完成简单爬虫
- Node.js学习之网络爬虫(使用cheerio抓取网页数据)
- node.js使用cheerio制作网络爬虫
- node.js使用cheerio制作网络爬虫
- 使用node.js cheerio抓取网页数据
- 使用node.js cheerio抓取网页数据
- 使用node.js cheerio抓取网页数据
- Node.js使用cheerio抓取网页数据DEMO
- superagent 抓取网页 cheerio 分析网页
- node.js 爬虫乱码问题 cheerio
- Node.Js cheerio模块简单API
- nodeJs -- 基于Express、superagent 和 cheerio
- node js简单爬虫实现
- Node.js:request+cheerio爬虫爬取免费代理
- node.js:利用cheerio编写的小爬虫程序
- 使用sync-request和cheerio写爬虫
- jsp内容
- HDOJ 1420 Prepared for New Acmer(DP)
- c语言
- iOS block代码块强引用问题
- 利用Python爬虫,抓取淘宝MM照片
- node.js 学习笔记003 :使用superagent和cheerio实现简单网页爬虫
- 配置CPU caffe全过程总结
- android gen目录相关
- 转载/VMware Workstation环境下的Linux网络设置/适用于无线网络
- DLL注入相关
- SSH 整合关键配置文件
- 营销型网站特点
- PDF转Word的方法(高效、美观)
- Eclipse and IDEA 快捷键对比