Node.jsを使用して、次のWebページのHTMLコンテンツを取得しようとする場合:
eternagame.wikia.com/wiki/EteRNA_Dictionary
次のエラーが発生します。
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
私はすでにこのエラーをstackoverflowで調べましたが、これはnode.jsがDNSからサーバーを見つけられないためだと思いました(私はそう思います)。ただし、私のコードはで完全に動作するため、これがなぜかはわかりませんwww.google.com。
ここに私のコードがあります(ホストが変更されていることを除いて、非常に類似した質問から実際にコピーして貼り付けました):
var http = require("http");
var options = {
host: 'eternagame.wikia.com/wiki/EteRNA_Dictionary'
};
http.get(options, function (http_res) {
// initialize the container for our data
var data = "";
// this event fires many times, each time collecting another piece of the response
http_res.on("data", function (chunk) {
// append this chunk to our growing `data` var
data += chunk;
});
// this event fires *one* time, after all the `data` events/chunks have been gathered
http_res.on("end", function () {
// you can use res.send instead of console.log to output via express
console.log(data);
});
});
ここに私がコピーして貼り付けたソースがあります:ExpressjsでWebサービスを呼び出す方法は?
node.jsでモジュールを使用していません。
読んでくれてありがとう。
var http = require("http");か、var https = require("https");リモートホストに基づいて
ENOTFOUND 意味ですか?