【重学Node.js 第4篇】实现一个简易爬虫&启动定时任务
实现一个简易爬虫&启动定时任务 课程介绍看这里: https://www.cnblogs.com/zhangran/p/11963616.html 项目github地址: https://github.com/hellozhangran/happy-egg-server 爬虫 目前 node.js 爬虫工具比较火的有 node-crawler puppeteer 。不过我目前没打算用这些,因为至少现在我们的项目还用不到。只要能发送请求、解析dom我们就能自己实现一个爬虫。所以我选择了axios + cheerio来自己写爬虫。 获取博客园的推荐文章 首先我们用 axios + cheerio 来获取博客园的首页编辑推荐文章,并解析出这篇文章的正文部分。 // controller/crawler.js 文件 const axios = require('axios'); const cheerio = require('cheerio'); // articleCtrl是一个写好了的controller,里面有存储数据到mongo的逻辑。 const articleCtrl = require('./article'); async function cnblogs () { const res = await axios.get('https://www.cnblogs.com/