PhantomJS使用基本auth返回null进行评估
我正在尝试在基本始终为auth的页面上使用PhantomJS,例如,此页
I am trying to use PhantomJS on a page with basic always auth, for example, this page
http://alexturpin.net/auth ( test:rosebud
)
使用以下代码
var webpage = require('webpage');
page = webpage.create();
page.settings = {
userName: "test",
password: "rosebud"
};
page.open("http://alexturpin.net/auth/", function(status) {
console.log(status);
var retval = page.evaluate(function() {
return "test";
});
console.log(retval);
});
我得到这个输出
$ phantomjs test.js
success
null
无论我尝试什么,评估
将继续返回 null
,即使该页面似乎已被打开,因为状态
包含成功
。
Whatever I try, evaluate
will keep returning null
, even though the page seems to have been opened fine because status
contains "success"
.
如果我决定开启没有基本身份验证的页面,如 http://alexturpin.net/noauth ,我仍然得到相同的结果。只有当我在打开页面之前完全删除身份验证设置时才能正常工作。
If I decide to open a page with no basic auth, like http://alexturpin.net/noauth, I still get the same results. Only when I finally remove the authentication settings altogether before opening the page does it work.
使用身份验证设置似乎与评估冲突
。这是PhantomJS中的一个错误,还是我错过了什么?
The use of authentication settings seem to be conflicting with the evaluate
. Is this a bug in PhantomJS, or did I miss something?
使用该语法,您将清除设置对象,替换只有 userName
和密码
。使用该代码进行设置:
With that syntax you are wiping out the settings object, replacing it with only userName
and password
. Use that code to set them:
page.settings.userName = "test";
page.settings.password = "rosebud";
可能PhantomJS应该更好地处理,即不依赖设置
默认对象。
Probably PhantomJS should handle that better, i.e. not rely on the settings
object for defaults.