gpt4 book ai didi

node.js - 错误 : getaddrinfo ENOTFOUND parishackers. 组织 parishackers.org:80

转载 作者:太空宇宙 更新时间:2023-11-04 00:09:03 28 4
gpt4 key购买 nike

错误:getaddrinfo ENOTFOUND parishackers.org parishackers.org:80 发生错误。我写了代码,

var Crawler = require("node-webcrawler");
var url = require('url');

var c = new Crawler({
maxConnections : 10,
// This will be called for each crawled page
callback : function (error, result, $) {
// $ is Cheerio by default
//a lean implementation of core jQuery designed specifically for the server
if(error){
console.log(error);
}else{
console.log($("title").text());
}
}
});

// Queue just one URL, with default callback
c.queue('http://www.amazon.com');

// Queue a list of URLs
c.queue(['http://www.google.com/','http://www.yahoo.com']);

// Queue URLs with custom callbacks & parameters
c.queue([{
uri: 'http://parishackers.org/',
jQuery: false,

// The global callback won't be called
callback: function (error, result) {
if(error){
console.log(error);
}else{
console.log('Grabbed', result.body.length, 'bytes');
}
}
}]);

// Queue some HTML code directly without grabbing (mostly for tests)
c.queue([{
html: '<p>This is a <strong>test</strong></p>'
}]);

但是当我运行代码时,谷歌雅虎Amazon.com:电子产品、服装、电脑、书籍、DVD 等在线购物

{ Error: getaddrinfo ENOTFOUND parishackers.org parishackers.org:80
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'parishackers.org',
host: 'parishackers.org',
port: 80 }

发生错误。我认为程序抓取了一部分数据,但我不知道为什么程序可以完全做到这一点。我安装了类似 npm install node-webcrawler 的库。我读了另一个网站,所以我认为这个错误是由于链接错误而发生的,对吧?我应该如何解决这个问题?我的代码有什么问题?

最佳答案

由于无效域名 http://parishackers.org 而引发错误 (getaddrinfo ENOTFOUND parishackers.org parishackers.org:80) 。使用有效的 url 链接,您的 Node 网络爬虫将像魅力一样工作。修改了代码片段供您引用

var Crawler = require("node-webcrawler");
var url = require('url');

var c = new Crawler({
maxConnections : 10,
// This will be called for each crawled page
callback : function (error, result, $) {
// $ is Cheerio by default
//a lean implementation of core jQuery designed specifically for the server
if(error){
console.log(error);
}else{
console.log($("title").text());
}
}
});

// Queue just one URL, with default callback
c.queue('http://www.amazon.com');

// Queue a list of URLs
c.queue(['http://www.google.com/','http://www.yahoo.com']);

// Queue URLs with custom callbacks & parameters
c.queue([{
uri: 'http://www.amazon.com',
jQuery: false,

// The global callback won't be called
callback: function (error, result) {
if(error){
console.log(error);
}else{
console.log('Grabbed', result.body.length, 'bytes');
}
}
}]);

// Queue some HTML code directly without grabbing (mostly for tests)
c.queue([{
html: '<p>This is a <strong>test</strong></p>'
}]);

关于node.js - 错误 : getaddrinfo ENOTFOUND parishackers. 组织 parishackers.org:80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50812405/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com