Node中内置

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

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

1
2
3
4
5
6
7
8
9
10
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';
});<br>打印结果如下如下图

 

posted @   热心市民~菜先生  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示