nodejs一括ダウンロード画像
15326 ワード
サンプルコードは以下の通りです.
var url_data = ["https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-1-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-2-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-3-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-4-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-5-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-6-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-7-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-8-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-9-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-10-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-11-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-12-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-13-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-14-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-15-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-16-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-17-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-18-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-19-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-20-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-21-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-22-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-23-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-24-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-25-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-26-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-27-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-28-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-29-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-30-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-31-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-32-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-33-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-34-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-35-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-36-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-37-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-38-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-39-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-40-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-41-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-42-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-43-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-44-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-45-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-46-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-47-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-48-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-49-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-50-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-51-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-52-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-53-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-54-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-55-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-56-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-57-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-58-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-59-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-60-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-61-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-62-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-63-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-64-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-65-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-66-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-67-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-68-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-69-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-70-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-71-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-72-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-73-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-74-1024.jpg?cb=1493904450", "https://image.slidesharecdn.com/everythingyouneedtoknowaboutmysqlgroupreplication-170504132319/95/everything-you-need-to-know-about-mysql-group-replication-75-1024.jpg?cb=1493904450"];
var request = require('request')
var fs = require('fs')
var path = require('path')
var url = require('url');
const dstpath = "./mgr_img"
function mkdirSync(dirname) {
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
}
}
return false
}
function downloadUrl(urlList) {
mkdirSync(dstpath);
for (const url_item of urlList) {
const arg = url.parse( url_item );
const fileName = arg.pathname.split('/').slice(-1)[0];
const download_dstpath = dstpath + '/' + fileName
request(url_item).pipe(fs.createWriteStream(download_dstpath))
}
}
downloadUrl(url_data);