以下是我尝试使用PhantomJS加载的网址:http://shop.karinelecchi.fr/collections/jupes-robes/products/jalousie
这是我的代码:
var fs = require("fs");
var system = require("system");
var page = require('webpage').create();
page.settings.userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1;+http://www,google,com/bot.html)";
page.settings.loadImages = false;
var url = "http://shop.karinelecchi.fr/collections/jupes-robes/products/jalousie";
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(url, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
console.log('Yiha! load the address!');
phantom.exit();
}
});
我的输出:"无法加载地址"
任何猜测? THX
答案 0 :(得分:2)
这里有一个网站,解释了如何跟踪网址加载失败:https://newspaint.wordpress.com/2013/04/25/getting-to-the-bottom-of-why-a-phantomjs-page-load-fails/
万一网站出现故障,我将在此处复制有关如何追踪这些问题的重要细节:
在调用page.open()之前,添加以下代码:
page.open(
"http://www.nosuchdomain/",
function (status) {
if ( status !== 'success' ) {
console.log(
"Error opening url \"" + page.reason_url
+ "\": " + page.reason
);
phantom.exit( 1 );
} else {
console.log( "Successful page open!" );
phantom.exit( 0 );
}
}
);
现在您可以在page.open()回调中打印出问题的原因,例如:
Error opening url "http://www.nosuchdomain/": Host www.nosuchdomain not found
此脚本输出以下内容:
page
请注意,onError
还有一个fh = new FileHandle(Infor.linkScreenShot);
活动,您可以在其中获得更多信息。