本文使用的是node来进行爬虫操作。
node中文网有http.get方法,并有案例:
const http=require('http');
http.get('http://pic.5tu.cn/photo/rw/rw_nrm.htm', (res) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
});
res.on('end', () => {
});
}).on('error', (e) => {
console.error(`Got error: ${e.message}`);
});
cheerio
用jquery语法 分析字符串html结构
一般用于爬虫分析
1.首先需要初始化一下
2、下载cheerio依赖
npm i cheerio -S
3、使用npmjs.com可以在官网看见cheerio的相关内容
在使用之前一定要导入 cheerio
否则会报错
在res.on中写入cheerio
由于只能够获取一条数据,不可取
最后在node中使用命令
即可看见数据