【问题标题】:Selenium Chrome Error: You are using an unsupported command-line flag: --ignore-certifcate-errorsSelenium Chrome 错误:您正在使用不受支持的命令行标志:--ignore-certifcate-errors
【发布时间】:2018-08-11 15:24:15
【问题描述】:

好的,我正在学习 Web Scraping 并且对 Java 很熟悉,因此我选择了 Jsoup,它是一个 Web Scraping 库。我计划抓取A CodeChef contest problem(这只是一个编码问题),但我发现抓取所有显示的内容很困难,因为其中大部分是动态源,所以这是不可能的。所以我使用 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());

错误(在 chrome 中):

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

我尝试了Chrome Error: You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer 的以下解决方案,我安装了最新的 chromedriver,但它没有解决我的错误。

我还尝试按照 Pass driver ChromeOptions and DesiredCapabilities? 添加 Desired Capabilities(现已弃用)和 ChromeOptions,但同样的错误仍然存​​在。

提前致谢!

【问题讨论】:

    标签: java selenium web-scraping google-chrome-devtools selenium-chromedriver


    【解决方案1】:

    错误说明了一切:

    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 Uninstaller 将其卸载并安装最新的 GA 和发布版本的 Web 浏览器
    • 进行系统重启
    • 执行你的 @Test

    【讨论】:

    • 我尝试了以上所有方法,但仍然显示错误。是否有任何忽略证书的具体论据?
    • 我已经尝试了一切(除了更新我的浏览器),对我来说似乎是浏览器版本问题。无论如何,我搬到了 HTMLUnit,这对我来说非常好!
    猜你喜欢
    • 1970-01-01
    • 2015-11-09
    • 2017-09-14
    • 1970-01-01
    • 2014-08-01
    • 2017-06-28
    • 2014-09-12
    • 1970-01-01
    • 2014-07-21
    相关资源
    最近更新 更多