尝试使用npm node-fetch从下方链接获取html时,出现以下错误:
我正在使用以下代码片段:无法获取页面:{FetchError:请求 https://www1.nseindia.com/marketinfo/companyTracker/compInfo.jsp?symbol=TCS&series=EQ 失败,原因:read ECONNRESET at ClientRequest
const DomParser = require("dom-parser");
const parser = new DomParser();
const fetch = require("node-fetch");
router.get("/info", (req, res, next) => {
var url =
"https://www1.nseindia.com/marketinfo/companyTracker/compInfo.jsp?symbol=TCS&series=EQ";
fetch(url)
.then(function(response) {
// When the page is loaded convert it to text
return response.text();
})
.then(function(html) {
// Initialize the DOM parser
// Parse the text
var doc = parser.parseFromString(html, "text/html");
// You can now even select part of that html as you would in the regular DOM
// Example:
// var docArticle = doc.querySelector('article').innerHTML;
console.log(doc);
})
.catch(function(err) {
console.log("Failed to fetch page: ", err);
});
});
在每次调用/info时,该响应会在显示错误之前被记录几次,现在它每次都抛出错误。
我已经在repl在线编辑器中尝试了这个代码片段,它返回Promise {pending}
。