最近在用webdrive,selenium做爬虫。发现通过webdriver打开http的网址可以正常打开,打开https的网址就会提示链接不安全,缺少证书。最后通过查阅资料发现需要设置profile。
具体代码:
$host = 'http://localhost:4444/wd/hub';
$profile = new FirefoxProfile();
$profile->setPreference('security.enterprise_roots.enabled', true);//设置下profile参数可以正常访问https
$caps = DesiredCapabilities::firefox();
$caps->setCapability(FirefoxDriver::PROFILE, $profile);
$driver = RemoteWebDriver::create($host, $caps);
$driver->get('https://www.baidu.com');