Authentication PhantomJS 1.9.1版-代理身份验证问题
有人能帮我一下吗? 我花了相当多的时间设置PhantomJS来保存特定网页的JPG,它工作得非常好,直到我将它部署到一台通过代理访问网络的机器上。 现在,无论我尝试什么,我都无法正确地获得身份验证? 有人能做到这一点吗 我正在使用命令行参数: --proxy=xx.xx.xx.xx:8080 --代理类型=http --proxyAuth=myusername:mypassword 我已经检查了代理(TMG),它仍然坚持我的用户名是匿名的,而不是我使用命令行发送的用户名 通过--debug,我可以看到proxy、proxyType和proxyAuth都已正确填充,因此PhantomJS可以理解命令行,但在运行时,它仍然返回“proxy需要身份验证” 我哪里做错了 谢谢你阅读这篇文章,希望能帮助我Authentication PhantomJS 1.9.1版-代理身份验证问题,authentication,proxy,phantomjs,Authentication,Proxy,Phantomjs,有人能帮我一下吗? 我花了相当多的时间设置PhantomJS来保存特定网页的JPG,它工作得非常好,直到我将它部署到一台通过代理访问网络的机器上。 现在,无论我尝试什么,我都无法正确地获得身份验证? 有人能做到这一点吗 我正在使用命令行参数: --proxy=xx.xx.xx.xx:8080 --代理类型=http --proxyAuth=myusername:mypassword 我已经检查了代理(TMG),它仍然坚持我的用户名是匿名的,而不是我使用命令行发送的用户名 通过--debug,我可
顺便说一句,我使用的是Windows7-64位的好的,所以我在这方面做了大量的挖掘工作,并使其正常工作。所以我想我会公布我的发现,以防它可能会帮助其他人 当我四处搜索时发现的一件事是,有一点关于在JS提交的用于驱动PhantomJS的标题中包含以下内容的讨论:
page.customHeaders={'Authorization': 'Basic '+btoa('username:password')};
而不是使用
page.settings.userName = 'username';
page.settings.password = 'password';
这是行不通的。请参阅
如果您在代理上使用基本级别的身份验证,这是可以接受的。如果您使用的是集成身份验证,那么它将不起作用,因为这仍然需要NTLM/Kerberos或其他任何东西
解决方法是更改客户端上的设置
您需要允许客户端访问外部世界,而无需通过代理路由。当然,在TMG中,这是通过更改应用于安装在客户机硬件上的客户机网络软件的设置来实现的
通过允许PhantomJS可执行文件绕过代理,您将克服我和许多其他人遇到的问题,但您仍然会遇到一些问题,因为您刚刚破坏了系统安全性,因此请注意并希望有一个处理NTLM/Kerberos的新版本PhantomJS
或者,将您的代理更改为使用基本身份验证,这将允许customHeaders解决方案的使用如上所述,但这对您的安全性来说可能比允许客户端绕过代理更大。好的,因此我在这方面做了大量的挖掘,并使其正常工作。所以我想我会公布我的发现,以防它可能会帮助其他人
var page = require('webpage').create(),
system = require('system'),
fs = require('fs'),
fileName = 'phantomjs',
extension = 'log',
file = fs.open(fileName + '.' + extension, 'w'),
address,
output,
delay,
version = phantom.version.major + '.'
+ phantom.version.minor + '.'
+ phantom.version.patch ;
if (system.args.length === 1){
console.log('Usage: example.js <some URL> delay');
phantom.exit();
}
// Handle the command line arguments
address = system.args[1];
output = system.args[2];
delay = system.args[3];
// Write the Headers into the log file
file.writeLine("PhantomJS version: " + version);
file.writeLine("Opening page: " + address);
file.writeLine("Writing image to: " + output);
file.writeLine("Applying a delay of: " + delay + " milliseconds");
function quit(reason, value) {
console.log("Quit: " + reason);
file.writeLine("Quit: " + reason);
file.close();
if (value !== 1){
// If there has been an error reported, stick a datetime stamp on the log to retain it
var d = new Date();
var dateString = d.getFullYear().toString() +
((d.getMonth() + 1) <= 9 ? '0' : '') + (d.getMonth() + 1).toString() +
(d.getDate() <= 9 ? '0' : '') + d.getDate().toString() +
(d.getHours() <= 9 ? '0' : '') + d.getHours().toString() +
(d.getMinutes() <= 9 ? '0' : '') + d.getMinutes().toString() +
(d.getSeconds() <= 9 ? '0' : '') + d.getSeconds().toString();
fs.move(fileName + '.' + extension, fileName + '_' + dateString + '.' + extension);
}
phantom.exit(value);
}
page.onResourceError = function(resourceError) {
page.reason = resourceError.errorString;
page.reason_url = resourceError.url;
};
page.onError = function (msg, trace) {
console.log(msg);
file.writeLine(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
//file.writeLine(' ', item.file, ':', item.line);
})
quit("Failed", 0);
}
page.onResourceRequested = function (request) {
file.writeLine('Request: ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
file.writeLine('Receive: ' + JSON.stringify(response, undefined, 4));
};
// Set a user agent - if required
//page.settings.userAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; .NET CLR 1.1.4322)';
// And open the page
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address: \"' + page.reason_url + '\": ' + page.reason);
file.writeLine('Unable to load the address: \"' + page.reason_url + '\": ' + page.reason);
quit("Failed", 0);
}
else {
window.setTimeout(function() {
console.log('Saving the page!');
file.writeLine('Saving the page!');
page.render(output);
quit("Finished", 1);
}, delay);
}
});
当我四处搜索时发现的一件事是,有一点关于在JS提交的用于驱动PhantomJS的标题中包含以下内容的讨论:
page.customHeaders={'Authorization': 'Basic '+btoa('username:password')};
而不是使用
page.settings.userName = 'username';
page.settings.password = 'password';
这是行不通的。请参阅
如果您在代理上使用基本级别的身份验证,这是可以接受的。如果您使用的是集成身份验证,那么它将不起作用,因为这仍然需要NTLM/Kerberos或其他任何东西
解决方法是更改客户端上的设置
您需要允许客户端访问外部世界,而无需通过代理路由。当然,在TMG中,这是通过更改应用于安装在客户机硬件上的客户机网络软件的设置来实现的
通过允许PhantomJS可执行文件绕过代理,您将克服我和许多其他人遇到的问题,但您仍然会遇到一些问题,因为您刚刚破坏了系统安全性,因此请注意并希望有一个处理NTLM/Kerberos的新版本PhantomJS
或者,将代理更改为使用基本身份验证,这将允许对customHeaders解决方案的使用如上所述,但这对您的安全性可能比允许客户端绕过代理更大。var page=require('webpage')。create(),
var page = require('webpage').create(),
system = require('system'),
fs = require('fs'),
fileName = 'phantomjs',
extension = 'log',
file = fs.open(fileName + '.' + extension, 'w'),
address,
output,
delay,
version = phantom.version.major + '.'
+ phantom.version.minor + '.'
+ phantom.version.patch ;
if (system.args.length === 1){
console.log('Usage: example.js <some URL> delay');
phantom.exit();
}
// Handle the command line arguments
address = system.args[1];
output = system.args[2];
delay = system.args[3];
// Write the Headers into the log file
file.writeLine("PhantomJS version: " + version);
file.writeLine("Opening page: " + address);
file.writeLine("Writing image to: " + output);
file.writeLine("Applying a delay of: " + delay + " milliseconds");
function quit(reason, value) {
console.log("Quit: " + reason);
file.writeLine("Quit: " + reason);
file.close();
if (value !== 1){
// If there has been an error reported, stick a datetime stamp on the log to retain it
var d = new Date();
var dateString = d.getFullYear().toString() +
((d.getMonth() + 1) <= 9 ? '0' : '') + (d.getMonth() + 1).toString() +
(d.getDate() <= 9 ? '0' : '') + d.getDate().toString() +
(d.getHours() <= 9 ? '0' : '') + d.getHours().toString() +
(d.getMinutes() <= 9 ? '0' : '') + d.getMinutes().toString() +
(d.getSeconds() <= 9 ? '0' : '') + d.getSeconds().toString();
fs.move(fileName + '.' + extension, fileName + '_' + dateString + '.' + extension);
}
phantom.exit(value);
}
page.onResourceError = function(resourceError) {
page.reason = resourceError.errorString;
page.reason_url = resourceError.url;
};
page.onError = function (msg, trace) {
console.log(msg);
file.writeLine(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
//file.writeLine(' ', item.file, ':', item.line);
})
quit("Failed", 0);
}
page.onResourceRequested = function (request) {
file.writeLine('Request: ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
file.writeLine('Receive: ' + JSON.stringify(response, undefined, 4));
};
// Set a user agent - if required
//page.settings.userAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; .NET CLR 1.1.4322)';
// And open the page
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address: \"' + page.reason_url + '\": ' + page.reason);
file.writeLine('Unable to load the address: \"' + page.reason_url + '\": ' + page.reason);
quit("Failed", 0);
}
else {
window.setTimeout(function() {
console.log('Saving the page!');
file.writeLine('Saving the page!');
page.render(output);
quit("Finished", 1);
}, delay);
}
});
系统=要求(“系统”),
fs=需要('fs'),
fileName='phantomjs',
扩展名='log',
file=fs.open(文件名+'。+扩展名'w'),
地址:,
产出,
延迟
version=phantom.version.major+'。'
+phantom.version.minor+'。'
+phantom.version.patch;
if(system.args.length==1){
log('Usage:example.js delay');
phantom.exit();
}
//处理命令行参数
地址=system.args[1];
输出=系统参数[2];
延迟=系统参数[3];
//将标题写入日志文件
writeLine(“PhantomJS版本:”+版本);
文件写入线(“起始页:“+地址”);
file.writeLine(“将图像写入:”+输出);
writeLine(“应用延迟:“+delay+”毫秒”);
函数退出(原因、值){
console.log(“退出:+原因”);
file.writeLine(“退出:+原因”);
file.close();
如果(值!==1){
//如果报告了错误,请在日志上粘贴日期时间戳以保留它
var d=新日期();
var dateString=d.getFullYear().toString()+
((d.getMonth()+1)var page=require('webpage')。create(),
系统=要求(“系统”),
fs=需要('fs'),
fileName='phantomjs',
扩展名='log',
file=fs.open(文件名+'。+扩展名'w'),
地址:,
产出,
延迟
version=phantom.version.major+'。'
+phantom.version.minor+'。'
+phantom.version.patch;
if(system.args.length==1){
log('Usage:example.js delay');
phantom.exit();
}
//处理命令行参数
地址=system.args[1];
输出=系统参数[2];
延迟=系统参数[3];
//将标题写入日志文件
writeLine(“PhantomJS版本:”+版本);
文件写入线(“起始页:“+地址”);
file.writeLine(“将图像写入:”+输出);
file.writeLine(“应用