今天就跟大家聊聊有關(guān)使用Node.js怎么批量下載圖片,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)主營興化網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),興化h5小程序制作搭建,興化網(wǎng)站營銷推廣歡迎興化等地區(qū)企業(yè)咨詢首先要獲取到圖片鏈接:
const img = [ "/file/tupian/20230213/7732.jpg", "/file/tupian/20230213/7733.jpg", "/file/tupian/20230213/7734.jpg", "/file/tupian/20230213/7735.jpg", "/file/tupian/20230213/7736.jpg", "/file/tupian/20230213/7737.jpg", "/file/tupian/20230213/7738.jpg", "/file/tupian/20230213/7739.jpg", "/file/tupian/20230213/7740.jpg", "/file/tupian/20230213/7741.jpg", "/file/tupian/20230213/7742.jpg", "/file/tupian/20230213/7743.jpg", "/file/tupian/20230213/7744.jpg", "/file/tupian/20230213/7745.jpg", "/file/tupian/20230213/7746.jpg", "/file/tupian/20230213/7747.jpg", "/file/tupian/20230213/7748.jpg", "/file/tupian/20230213/7749.jpg", "/file/tupian/20230213/7750.jpg", "/file/tupian/20230213/7751.jpg", "/file/tupian/20230213/7752.jpg", "/file/tupian/20230213/7753.jpg", "/file/tupian/20230213/7754.jpg", "/file/tupian/20230213/7755.jpg", "/file/tupian/20230213/7756.jpg", "/file/tupian/20230213/7757.jpg", "/file/tupian/20230213/7758.jpg", "/file/tupian/20230213/7759.jpg", "/file/tupian/20230213/7760.jpg", "/file/tupian/20230213/7761.jpg", "/file/tupian/20230213/7762.jpg", "/file/tupian/20230213/7763.jpg", "/file/tupian/20230213/7764.jpg", "/file/tupian/20230213/7765.jpg", "/file/tupian/20230213/7766.jpg", "/file/tupian/20230213/7767.jpg", "/file/tupian/20230213/7768.jpg", "/file/tupian/20230213/7769.jpg", "/file/tupian/20230213/7770.jpg", "/file/tupian/20230213/7771.jpg", "/file/tupian/20230213/7772.jpg", "/file/tupian/20230213/7774.jpg" ];
批量下載圖片:
var fs = require('fs'); var request = require("request"); img.forEach(src => { var writeStream = fs.createWriteStream(src.split('/2019/08/')[1]); var readStream = request(src) readStream.pipe(writeStream); readStream.on('end', function() { console.log('文件下載成功'); }); readStream.on('error', function() { console.log(1); // console.log("錯誤信息:" + err) }) writeStream.on("finish", function() { console.log("文件寫入成功"); writeStream.end(); }); });
看完上述內(nèi)容,你們對使用Node.js怎么批量下載圖片有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。