Javascript phantomjs 中的代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11334681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Proxy in phantomjs
提问by Torv
I cant understand how to using proxies in phantomjs, i tried
我无法理解如何在 phantomjs 中使用代理,我试过了
phantomjs example.js --proxy="ip:port"
phantomjs example.js --proxy="ip:port"
phantomjs example.js --proxy=ip:port
phantomjs example.js --proxy=ip:port
phantomjs example.js --proxy=ip:port --proxy-type=http
phantomjs example.js --proxy=ip:port --proxy-type=http
but i see only my ip=(
但我只看到我的 ip=(
No any output, also if proxy ip apriori invalid.
没有任何输出,如果代理 ip apriori 无效。
example.js:
例子.js:
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.onLoadFinished = function(status){
if (!status){
console.log('fail');
phantom.exit();
}
page.render("1.png");
phantom.exit();
};
page.open("http://whoer.net/");
what obvious thing i forgot? Thanks.
我忘记了什么明显的事情?谢谢。
回答by Torv
As i said i forgot one obvious thing - arguments for phantomjs must be after command "phantomjs" not after script name. Correct variant:
正如我所说,我忘记了一件显而易见的事情 - phantomjs 的参数必须在命令“phantomjs”之后,而不是在脚本名称之后。正确的变体:
phantomjs --proxy=ip:port example.js
phantomjs --proxy=ip:port example.js
回答by Torv
This code is for authentication with username& password. As well as, save result in sample.txt:
此代码用于使用用户名和密码进行身份验证。此外,将结果保存在sample.txt 中:
phantomjs --proxy=Ip:Port --proxy-auth=User:Pass App.js > sample.txt