标签:each att var down ejs set let www lang
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下载完成")
})
}
})
})
标签:each att var down ejs set let www lang
原文地址:https://www.cnblogs.com/botaoJava/p/14827675.html