PhantonJS/Selenium自定义用户代理问题
通过阅读PhantomJS和其他无头浏览器,我发现可以设置一个用户代理,我的基本代码:PhantonJS/Selenium自定义用户代理问题,selenium,selenium-webdriver,phantomjs,Selenium,Selenium Webdriver,Phantomjs,通过阅读PhantomJS和其他无头浏览器,我发现可以设置一个用户代理,我的基本代码: var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = false; driverService.LoadImages = true; driverService.ProxyType = "none"; var options = n
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = false;
driverService.LoadImages = true;
driverService.ProxyType = "none";
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10");
IWebDriver driver = new PhantomJSDriver(options);
using (var phantomDriver = new PhantomJSDriver(driverService))
{
// use code here...
}
我的问题是:
new PhantomJSDriver(driverService))
我正在设置要使用的CreateDefaultService,我不确定如何添加:
IWebDriver driver = new PhantomJSDriver(options);
要用吗?或者是按原样执行,这意味着我不需要在代码中的任何地方输入:驱动程序变量,任何帮助都将不胜感激。您需要同时使用选项和服务
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = false;
driverService.LoadImages = true;
driverService.ProxyType = "none";
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10");
using (var phantomDriver = new PhantomJSDriver(driverService, options))
{
// use code here...
}
您需要同时使用选项和服务
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = false;
driverService.LoadImages = true;
driverService.ProxyType = "none";
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10");
using (var phantomDriver = new PhantomJSDriver(driverService, options))
{
// use code here...
}