当前位置:网站首页>Nodejs crawler
Nodejs crawler
2022-07-06 15:59:00 【Star age Cao Botao】
nodejs You can also play with reptiles
Need to pass through npm Down in two modules .
npm init -y
npm install -S axios cheerio
establish index.js file
const cheerio = require("cheerio")
const axios = require("axios")
const fs = require("fs")
if (!fs.existsSync("download")) {
fs.mkdirSync("download", 777)
}
console.log(" Start crawling ")
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(" Start the download " + url)
axios.get(url, {
responseType: 'stream' }).then(resp => {
let writer = fs.createWriteStream("./download/" + index + ".png");
resp.data.pipe(writer);
console.log(index+".png Download complete ")
})
}
})
})
cmd Input
node index.js
You can see that the file has been downloaded
边栏推荐
猜你喜欢
洛谷P1102 A-B数对(二分,map,双指针)
程序员的你,有哪些炫技的代码写法?
差分(一维,二维,三维) 蓝桥杯三体攻击
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
毕业才知道IT专业大学生毕业前必做的1010件事
信息安全-安全编排自动化与响应 (SOAR) 技术解析
TCP的三次握手与四次挥手
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
力扣刷题记录
随机推荐
D - Function(HDU - 6546)女生赛
Determine the Photo Position
毕业才知道IT专业大学生毕业前必做的1010件事
0-1背包问题(一)
Cost accounting [18]
程序员的你,有哪些炫技的代码写法?
STM32 learning record: LED light flashes (register version)
1010 things that college students majoring in it must do before graduation
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
【练习-11】4 Values whose Sum is 0(和为0的4个值)
Alice and Bob (2021牛客暑期多校训练营1)
C语言是低级和高级的分水岭
渗透测试 ( 1 ) --- 必备 工具、导航
数据在内存中的存储&载入内存,让程序运行起来
Opencv learning log 13 corrosion, expansion, opening and closing operations
Cost accounting [21]
滲透測試 ( 1 ) --- 必備 工具、導航
Learning record: Tim - Basic timer
Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )