superagent 抓取网页cheerio 分析网页

    xiaoxiao2021-04-13  28

    学习使用 superagent 抓取网页学习使用 cheerio 分析网页

    superagent(http://visionmedia.github.io/superagent/ ) 是个 http 方面的库,可以发起 get 或 post 请求。

    cheerio(https://github.com/cheeriojs/cheerio ) 大家可以理解成一个 Node.js 版的 jquery,用来从网页中以 css selector 取数据,使用方式跟 jquery 一样一样的。

    SuperAgent —— Node 的 客户端请求

    var request = require('superagent'); request .post('/api/pet') .send({ name: 'Manny', species: 'cat' }) .set('X-API-Key', 'foobar') .set('Accept', 'application/json') .end(function(err, res){ if (res.ok) { alert('yay got ' + JSON.stringify(res.body)); } else { alert('Oh no! error ' + res.text); } });

    SuperAgent请求的默认方法为GET,所以你可可以简单地写如下代码:

    request('/search', function(res){ });
    转载请注明原文地址: https://ju.6miu.com/read-669098.html

    最新回复(0)