当前位置:网站首页>nodejs爬虫
nodejs爬虫
2022-07-06 09:25:00 【星时代曹波涛】
nodejs也可以玩爬虫
需要通过npm下在两个模块。
npm init -y
npm install -S axios cheerio
创建index.js文件
const cheerio = require("cheerio")
const axios = require("axios")
const fs = require("fs")
if (!fs.existsSync("download")) {
fs.mkdirSync("download", 777)
}
console.log("开始爬取")
axios.get("http://www.scsoul.top/list/1/20").then(r => {
const $ = cheerio.load(r.data)
$("img").each((index, item) => {
if (index != 0) {
var url = $(item).attr("src");
console.log("开始下载" + url)
axios.get(url, {
responseType: 'stream' }).then(resp => {
let writer = fs.createWriteStream("./download/" + index + ".png");
resp.data.pipe(writer);
console.log(index+".png下载完成")
})
}
})
})
cmd输入
node index.js
就可以看到文件已经被下载下来了
边栏推荐
- STM32 how to use stlink download program: light LED running light (Library version)
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- STM32 learning record: play with keys to control buzzer and led
- Cost accounting [14]
- China chart recorder market trend report, technology dynamic innovation and market forecast
- CSAPP shell lab experiment report
- JS --- detailed explanation of JS DOM (IV)
- Learning record: use stm32f1 watchdog
- Brief introduction to libevent
- 0-1背包問題(一)
猜你喜欢
随机推荐
CSAPP shell lab experiment report
JS --- BOM details of JS (V)
Accounting regulations and professional ethics [1]
Research Report on medical toilet industry - market status analysis and development prospect forecast
STM32学习记录:玩转按键控制蜂鸣器和LED
JS --- detailed explanation of JS DOM (IV)
Preface to the foundations of Hilbert geometry
LeetCode#118. Yanghui triangle
12306: mom, don't worry about me getting the ticket any more (1)
Stm32 dossiers d'apprentissage: saisie des applications
ucore lab 6
Accounting regulations and professional ethics [5]
Record of force deduction and question brushing
China earth moving machinery market trend report, technical dynamic innovation and market forecast
学习记录:TIM—电容按键检测
力扣刷题记录
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
ucore lab7
JS --- all basic knowledge of JS (I)
Flex --- detailed explanation of flex layout attributes








