Selenium Chrome 错误:您正在使用不受支持的命令行标志:--忽略证书错误



好的,所以我正在学习网页抓取并且对Java感到满意,因此我选择了Jsoup,这是一个网页抓取库。我计划抓取 CodeChef 竞赛问题(这只是一个编码问题),但我发现很难抓取所有显示的内容,这是不可能的,因为其中大部分都是动态源。所以我使用selenium来渲染JavaScript并获取简单的HTML页面,然后将其提供给JSOUP。

所以我尝试打印呈现的 HTML 页面只是为了验证,但在运行代码时出现以下错误:

我的代码:

File f = new File("<Path to chromedriver.exe>");
System.setProperty("webdriver.chrome.driver", f.getAbsolutePath());
WebDriver driver = new ChromeDriver();
driver.get("https://www.codechef.com/problems/FRGTNLNG");
System.out.println(driver.getPageSource());

错误(在镶边中):

You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer

我从Chrome错误中尝试了以下解决方案:您正在使用不受支持的命令行标志:--忽略证书错误。稳定性和安全性会受到影响,我安装了最新的chromedriver,但它没有解决我的错误。

我还尝试根据Pass驱动程序ChromeOptions和DesiredCapabilities添加所需功能(现已弃用)和ChromeOptions,但相同的错误仍然存在。

提前感谢!

错误说明了一切:

You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer

根据最佳编程实践,使用ChromeOptions类打开最大化的Chrome 浏览器,禁用信息栏禁用扩展程序,如下所示:

System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--test-type");
options.addArguments("--ignore-certificate-errors");
WebDriver driver =  new ChromeDriver(options);
driver.get("https://www.google.co.in");

此外,执行以下步骤:

  • 将 JDK 更新到最新版本JDK 8u162
  • Selenium-Java 客户端升级到v3.10.0
  • ChromeDriver升级到最新版本的ChromeDriver v2.35
  • 从 IDE 中清理项目空间
  • 运行CCleaner工具以清除所有操作系统琐事。
  • 如果您的基本 Web 浏览器版本太旧,请通过Revo 卸载程序将其卸载,并安装最新的 GA 和已发布版本的Web 浏览器
  • 重新启动系统
  • 执行您的@Test

最新更新