我有一个phantomJS脚本
var page = require('webpage').create();
var system = require('system');
page.settings.userAgent = 'SpecialAgent';
var i = 1;
var url = 'http://www.google.cz/?test=' + i;
console.log( "url='" + url + "'" );
page.open(url, function (status) {
if (status !== 'success') {
console.log( 'Unable to access network' );
} else {
console.log( 'Opened ok' );
phantom.exit();
}
});它工作得很好,但是当我在for循环中包装page.open时,
var page = require('webpage').create();
var system = require('system');
page.settings.userAgent = 'SpecialAgent';
//var i = 1;
for ( var i = 1; i <= 2; ++i ) {
var url = 'http://www.google.cz/?test=' + i;
console.log( "url='" + url + "'" );
page.open(url, function (status) {
if (status !== 'success') {
console.log( 'Unable to access network' );
} else {
console.log( 'Opened ok' );
phantom.exit();
}
});
}我得到了
无法接入网络
我认为这是因为它是并行执行的。我说的对吗?(phantom.exit()可能在错误的地方)如何等待处理page.open,然后执行下一次迭代?
发布于 2018-04-24 01:37:02
问题是PhantomJS版本< 1.9.8默认使用SSLv3,但由于大多数add服务器都禁用了SSLv3支持,因此需要显式添加--ssl-protocol=tlsv1 (或) --ssl-protocol=any命令行选项。
使用幻影you运行脚本时,添加以下命令行选项
phantomjs --ssl-protocol=any yourscript.js如果您仍然得到一个错误,它可能是由于SSL证书错误,使用--ignore-ssl-errors=yes选项应该继续加载页面,因为它将忽略所有ssl错误,包括恶意错误。
phantomjs --ssl-protocol=any --ignore-ssl-errors=yes yourscript.jshttps://stackoverflow.com/questions/26934486
复制相似问题