Node中内置

   superagent 是一个轻量的,渐进式的ajax api,可读性好,学习曲线低,内部依赖nodejs原生的请求api,适用于nodejs环境下

   cheerio是nodejs的抓取页面模块,为服务器特别定制的,快速、灵活、实施的jQuery核心实现。适合各种Web爬虫程序。相当于node.js中的jQuery

const superagent = require('superagent');
const cheerio = require('cheerio');

const url = 'https://www.ashley.cn/product/getProducts';
superagent.post(url, { space: 10, sort: 'id', page: 1 })
      .end((error, response) => {
        const $ = response.text; // 利用cheerio对页面进行解析
        console.log(JSON.parse($));
        ctx.body = 'hi, egg';
});
打印结果如下

 

如下图
posted @ 2023-04-24 17:07  热心市民~菜先生  阅读(7)  评论(0编辑  收藏  举报