【发布时间】:2021-01-19 16:18:44
【问题描述】:
我有大量的 URL (8000+) 我想从中下载图像。 我创建了一个脚本来下载文件,只要我将限制设置为大约 100。 如果我尝试下载更多内容,我会收到类似的错误
- (节点:6740)UnhandledPromiseRejectionWarning:错误:读取 ECONNRESET
- (节点:3808)UnhandledPromiseRejectionWarning:错误:连接 ETIMEDOUT
- (节点:7052)UnhandledPromiseRejectionWarning:错误:客户端网络套接字在建立安全 TLS 连接之前已断开
这是用 URL 读取我的 CSV 的代码:
const fotoDownload = require('./async-foto');
const csv = require('csv-parser');
const fs = require('fs');
const results = [];
fs.createReadStream('\\\\hk-nas02\\import\\Partij\\Files\\partij.csv')
.pipe(csv( { separator: ';'}))
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results.length)
let NoPartijen = results.length;
for(i = 0;i < 50; i++){
//console.log(results[i]);
itemno = i
path = '..\\files\\images\\'+results[i]['partij.VPARTIJNR']+'_'+results[i]['partij.PARTIJNR']+'_H.jpg';
console.log(path)
fotoDownload.fotoDownload(results[i]['partij.EXFOTOURL'], path, itemno)
}
console.log('Test');
});
并调用以下代码下载:
const util = require('util')
const fs = require('fs')
const axios = require("axios").default;
module.exports = {
fotoDownload: async (url, path, itemno) => {
try {
const response = await axios({
method: "GET",
url: url,
responseType: "stream",})
await response.data.pipe(fs.createWriteStream(path));
console.log('Start foto download' + itemno);
return;
} catch (err) {
throw new Error(err)
}
}
}
我假设我需要将数据切成块或其他东西,但我在这里有点迷失了。有人能把我引向正确的方向吗?
【问题讨论】:
标签: javascript node.js