我正在写一篇短文节点.js解析RSS提要、提取链接、将它们重新配置为所需的PDF链接,然后编写这些文件的代码段。代码如下所示:
var https = require('https');
var fs = require('fs');
const Parser = require("rss-parser");
let parser = new Parser();
parser.parseURL("https://regulations.justia.com/regulations/fedreg?limit=20&mode=atom")
.then((feed) => {
const base = "https://docs.regulations.justia.com/entries"
feed.items.forEach((item, i) => {
// Parsing to create PDF link...
const str = item.link;
let dates = str.substring(50, 60);
let newDates = dates.replace(/\//, "-").replace(/\//, "-");
let ending = str.substring(61).replace(".html",".pdf");
let fullString = `${base}/${newDates}/${ending}`;
// Fetching and saving the PDF file....
const file = fs.createWriteStream(`${item.title}.pdf`);
const request = https.get(fullString, (res) => {
res.pipe(file);
});
});
})
.catch((err) => console.log(err));
1) 和我的可写流有关。当我尝试根据
item.title
从RSS提要中,我每次都会遇到以下错误:
Error: ENOENT: no such file or directory, open 'Notice - Solicitation of Nominations for Appointment to the World Trade Center Health Program Scientific/Technical Advisory Committee (STAC).pdf'
这与项目标题中的括号或em破折号有关吗?如果不是,还有什么可能导致这个问题?
Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1135:19)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at TLSSocket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
这个错误通常是在我下载了很多PDF文件之后抛出的,但不是全部。在这个例子中,我可以改变什么来克服这些错误?谢谢你的帮助!