如何为幻影aws 提供用户代理定义,我目前正在使用aws服务器ec2实例上的以下命令运行
phantomjs --web-security=no --ssl-protocol=any --ignore-ssl-errors=true driver.js http://example.com发布于 2017-02-04 19:16:54
您只能在PhantomJS中以脚本(在示例中为driver.js)设置用户代理。关于它的文档:http://phantomjs.org/api/webpage/property/settings.html
如果希望在命令行中将用户代理传递给PhantomJS,则可以使用参数。在脚本中,您可以接受参数并将其设置为用户代理。您可以尝试下面的示例:
var webPage = require('webpage');
var system = require('system');
var page = webPage.create();
var userAgent = system.args[1];
page.settings.userAgent = userAgent;
console.log('user agent: ' + page.settings.userAgent);
phantom.exit();按以下方式运行:
$幻影NT ua.js "Mozilla/5.0 (WindowsNT6.1;WOW64) AppleWebKit/537.36 (KHTML,类似壁虎) Chrome/37.0.2062.120 Safari/537.36“
您将得到输出:
用户代理: Mozilla/5.0 (WindowsNT6.1;WOW64) AppleWebKit/537.36 (KHTML,类似壁虎) Chrome/37.0.2062.120 Safari/537.36
https://stackoverflow.com/questions/42026707
复制相似问题