无头铬+忽略证书错误

编程入门 行业动态 更新时间:2024-10-22 09:40:23
本文介绍了无头铬+忽略证书错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要获得无头镀铬以忽略证书错误。在无头模式下运行时,该选项将被忽略,并且在导航到https资源时,驱动程序返回空的html主体标签。

<< ; html xmlns =www.w3/1999/xhtml>< head>< / head>< body>< / body>< / html>

这就是我配置我的chrome驱动程序的方式。

ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments( - headless,--disable-gpu,--window-size = 1920,1200, - ignore-certificate-errors); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(ChromeOptions.CAPABILITY,chromeOptions); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true); cap.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true); chromeHeadlessDriver =新的ChromeDriver(cap);

此主题确认 - ignore-certificate-errors 是忽略无头模式。

他们提到 devtool协议。

这是我可以从java调用的东西吗?有没有其他的选择?

解决方案

medium by sahajamit

,我测试了下面的代码,它使用自签名证书 https:// badssl。 com /

ChromeOptions options = new ChromeOptions(); options.setExperimentalOption(useAutomationExtension,false); options.addArguments( - headless,--window-size = 1920,1200, - ignore-certificate-errors); DesiredCapabilities crcapabilities = DesiredCapabilities.chrome(); crcapabilities.setCapability(ChromeOptions.CAPABILITY,options); crcapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true); crcapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true); System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY,C:\\temp\\chrome\\chromedriver.log); System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,C:\\temp\\chrome\\chromedriver.exe); ChromeDriverService服务= null; try { service = new ChromeDriverService.Builder() .usingAnyFreePort() .withVerbose(true) .build(); service.start(); } catch(IOException e){ e.printStackTrace(); } RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(),crcapabilities); driver.get(self-signed.badssl/); System.out.println(driver.getPageSource()); driver.quit();

软件/框架版本

  • Google Chrome版本64.0.3282.186
  • Google Chrome驱动程序版本64.0.3282.186
  • Selenium版本3.11.0

I need to get headless chrome to ignore certificate errors. The option is ignored when running in headless mode, and the driver returns empty html body tags when navigating to an https resource.

<html xmlns="www.w3/1999/xhtml"><head></head><body></body></html>

This is how I am configuring my chrome driver.

ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors"); DesiredCapabilities cap=DesiredCapabilities.chrome(); cap.setCapability(ChromeOptions.CAPABILITY, chromeOptions); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); chromeHeadlessDriver = new ChromeDriver(cap);

This thread confirms that --ignore-certificate-errors is ignored in headless mode.

They mention about devtool protocol.

Is it something I can invoke from java? Are there any other alternatives?

解决方案

There is an excellent article on medium by sahajamit

and i have tested the below code, it works perfectly fine with self-signed certificate badssl/

ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("useAutomationExtension", false); options.addArguments("--headless", "--window-size=1920,1200","--ignore-certificate-errors"); DesiredCapabilities crcapabilities = DesiredCapabilities.chrome(); crcapabilities.setCapability(ChromeOptions.CAPABILITY, options); crcapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); crcapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "C:\\temp\\chrome\\chromedriver.log"); System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "C:\\temp\\chrome\\chromedriver.exe"); ChromeDriverService service = null; try { service = new ChromeDriverService.Builder() .usingAnyFreePort() .withVerbose(true) .build(); service.start(); } catch (IOException e) { e.printStackTrace(); } RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(),crcapabilities); driver.get("self-signed.badssl/"); System.out.println(driver.getPageSource()); driver.quit();

software/framework versions

  • Google Chrome Version 64.0.3282.186
  • Google Chrome Driver Version 64.0.3282.186
  • Selenium version 3.11.0

更多推荐

无头铬+忽略证书错误

本文发布于:2023-11-07 22:51:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无头   证书   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!