nodeJs爬取网络图片

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下载完成")
            })
        }
    })
})

nodeJs爬取网络图片

上一篇:python3+nltk3+matplotlib1.3中plot方法无法执行的解决办法


下一篇:WCF实现大文件上传