18720358503 在线客服 人才招聘 返回顶部
企业动态 技术分享 行业动态

小程序游戏怎么开发_Node.js完成批量下载图片简略

2021-01-06分享 "> 对不起,没有下一图集了!">
Node.js实现批量下载图片简单操作示例       这篇文章主要介绍了Node.js实现批量下载图片简单操作,结合实例形式分析了node.js批量下载图片的具体步骤与相关实现技巧,需要的朋友可以参考下

本文实例讲述了Node.js实现批量下载图片简单操作。分享给大家供大家参考,具体如下:

使用Node.js批量下载图片

首先要获取到图片链接:

const img = [
 "ywwl-jylesson/2019/08/522423.jpg",
 "ywwl-jylesson/2019/08/522692.jpg",
 "ywwl-jylesson/2019/08/522251.jpg",
 "ywwl-jylesson/2019/08/522242.jpg",
 "ywwl-jylesson/2019/08/522127.jpg",
 "ywwl-jylesson/2019/08/522344.jpg",
 "ywwl-jylesson/2019/08/522042.jpg",
 "ywwl-jylesson/2019/08/522096.jpg",
 "ywwl-jylesson/2019/08/522000.jpg",
 "ywwl-jylesson/2019/08/522453.jpg",
 "ywwl-jylesson/2019/08/522909.jpg",
 "ywwl-jylesson/2019/08/522599.jpg",
 "ywwl-jylesson/2019/08/522804.jpg",
 "ywwl-jylesson/2019/08/522517.jpg",
 "ywwl-jylesson/2019/08/522979.jpg",
 "ywwl-jylesson/2019/08/522758.jpg",
 "ywwl-jylesson/2019/08/522628.jpg",
 "ywwl-jylesson/2019/08/522176.jpg",
 "ywwl-jylesson/2019/08/522871.jpg",
 "ywwl-jylesson/2019/08/522504.jpg",
 "ywwl-jylesson/2019/08/522270.jpg",
 "ywwl-jylesson/2019/08/522469.jpg",
 "ywwl-jylesson/2019/08/522806.jpg",
 "ywwl-jylesson/2019/08/522281.jpg",
 "ywwl-jylesson/2019/08/522908.jpg",
 "ywwl-jylesson/2019/08/522769.jpg",
 "ywwl-jylesson/2019/08/522014.jpg",
 "ywwl-jylesson/2019/08/522956.jpg",
 "ywwl-jylesson/2019/08/522373.jpg",
 "ywwl-jylesson/2019/08/522282.jpg",
 "ywwl-jylesson/2019/08/522694.jpg",
 "ywwl-jylesson/2019/08/522011.jpg",
 "ywwl-jylesson/2019/08/522215.jpg",
 "ywwl-jylesson/2019/08/522382.jpg",
 "ywwl-jylesson/2019/08/522253.jpg",
 "ywwl-jylesson/2019/08/522008.jpg",
 "ywwl-jylesson/2019/08/522055.jpg",
 "ywwl-jylesson/2019/08/522773.jpg",
 "ywwl-jylesson/2019/08/522563.jpg",
 "ywwl-jylesson/2019/08/522797.jpg",
 "ywwl-jylesson/2019/08/522344.jpg",
 "ywwl-jylesson/2019/08/522545.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();

希望本文所述对大家node.js程序设计有所帮助。


"> 对不起,没有下一图集了!">
在线咨询