Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PhantomJS:在进行调用时指定用户代理_Phantomjs - Fatal编程技术网

PhantomJS:在进行调用时指定用户代理

PhantomJS:在进行调用时指定用户代理,phantomjs,Phantomjs,我使用PhantomJS调用网页,如下所示: page.open('http://example.com', function (s) { console.log(page.content); phantom.exit(); }); 我在Drupal Simpletests的上下文中使用它,它要求我设置一个特殊的USERAGENT,以便使用测试数据库而不是真实的数据库。我想通过特定的用户代理获取网页。例如,在使用Curl的PHP中,在进行Curl调用之前,我可以使用CURLOPT_US

我使用PhantomJS调用网页,如下所示:

page.open('http://example.com', function (s) {
  console.log(page.content);
  phantom.exit();
});
我在Drupal Simpletests的上下文中使用它,它要求我设置一个特殊的USERAGENT,以便使用测试数据库而不是真实的数据库。我想通过特定的用户代理获取网页。例如,在使用Curl的PHP中,在进行Curl调用之前,我可以使用CURLOPT_USERAGENT执行此操作

谢谢

Albert

我在phantomjs的文件中找到了答案:

var page=require('webpage').create();
console.log('默认的用户代理是'+page.settings.userAgent);
page.settings.userAgent='SpecialAgent';
第页打开('http://www.httpuseragent.org,功能(状态){
如果(状态!=“成功”){
console.log('无法访问网络');
}否则{
var ua=第页评估(函数(){
return document.getElementById('myagent').innerText;
});
控制台日志(ua);
}
phantom.exit();
});

我无法访问网络。我可以通过其他浏览器访问该网站。它是一个内部可访问的站点。我必须设置一些设置才能从Phantom访问。