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下载完成")
            })
        }
    })
})
posted @   星时代曹波涛  阅读(171)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· Ollama系列05:Ollama API 使用指南
· 为什么AI教师难以实现
点击右上角即可分享
微信分享提示