代理在phantomjs

Tor*_*orv 19 javascript phantomjs

我试着理解如何在phantomjs中使用代理

phantomjs example.js --proxy ="ip:port"

phantomjs example.js --proxy = ip:port

phantomjs example.js --proxy = ip:port --proxy-type = http

但我只看到我的ip =(

没有任何输出,如果代理ip apriori无效.

example.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/");
Run Code Online (Sandbox Code Playgroud)

我忘记了什么明显的事情?谢谢.

Tor*_*orv 46

正如我所说,我忘记了一个显而易见的事情 - phantomjs的参数必须在命令"phantomjs"之后,而不是在脚本名称之后.正确的变种:

phantomjs --proxy = ip:port example.js

  • 也为我工作:DI认为值得一提的是脚本左侧的参数将传递给phantomjs,脚本右侧的参数将传递给脚本本身(可通过`require('system')访问. `) (3认同)