Node.js实现批量下载图片简单操作示例
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要介绍了Node.js实现批量下载图片简单操作,结合实例形式分析了node.js批量下载图片的具体步骤与相关实现技巧,需要的朋友可以参考下
本文实例讲述了Node.js实现批量下载图片简单操作。分享给大家供大家参考,具体如下
使用Node.js批量下载图片
要获取到图片链接
const img = [ "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400506629423.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400540139692.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400540118251.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400540069242.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400681111127.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400703641344.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400854321042.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400847773096.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400859178000.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400865596453.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400902911909.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400953029599.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400989455804.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401005976517.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218400968714979.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401035049758.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401049432628.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401077574176.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401130741871.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401189588504.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401178924270.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401236159469.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401233410806.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401271226281.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401296600908.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401331496769.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401294723014.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401355737956.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401375565373.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401430489282.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401429130694.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401443905011.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401494231215.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401470554382.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401544523253.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401585803008.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401632787055.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401681076773.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401666198563.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401687089797.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401796465344.jpg", "http://yw-yx.oss--hangzhou.aliyuncs./ywwl-jylesson/2019/08/52218401847533545.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程序设计有所帮助。
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南