• <small id='K281t'></small><noframes id='K281t'>

    <tfoot id='K281t'></tfoot>

      <i id='K281t'><tr id='K281t'><dt id='K281t'><q id='K281t'><span id='K281t'><b id='K281t'><form id='K281t'><ins id='K281t'></ins><ul id='K281t'></ul><sub id='K281t'></sub></form><legend id='K281t'></legend><bdo id='K281t'><pre id='K281t'><center id='K281t'></center></pre></bdo></b><th id='K281t'></th></span></q></dt></tr></i><div id='K281t'><tfoot id='K281t'></tfoot><dl id='K281t'><fieldset id='K281t'></fieldset></dl></div>
      <legend id='K281t'><style id='K281t'><dir id='K281t'><q id='K281t'></q></dir></style></legend>

          <bdo id='K281t'></bdo><ul id='K281t'></ul>
      1. 在 Ubuntu Server 上无头运行 Chromedriver

        Running Chromedriver on Ubuntu Server headlessly(在 Ubuntu Server 上无头运行 Chromedriver)
          <tbody id='yRuTM'></tbody>
        <i id='yRuTM'><tr id='yRuTM'><dt id='yRuTM'><q id='yRuTM'><span id='yRuTM'><b id='yRuTM'><form id='yRuTM'><ins id='yRuTM'></ins><ul id='yRuTM'></ul><sub id='yRuTM'></sub></form><legend id='yRuTM'></legend><bdo id='yRuTM'><pre id='yRuTM'><center id='yRuTM'></center></pre></bdo></b><th id='yRuTM'></th></span></q></dt></tr></i><div id='yRuTM'><tfoot id='yRuTM'></tfoot><dl id='yRuTM'><fieldset id='yRuTM'></fieldset></dl></div>

            <bdo id='yRuTM'></bdo><ul id='yRuTM'></ul>

            <small id='yRuTM'></small><noframes id='yRuTM'>

              <tfoot id='yRuTM'></tfoot>
              • <legend id='yRuTM'><style id='yRuTM'><dir id='yRuTM'><q id='yRuTM'></q></dir></style></legend>

                • 本文介绍了在 Ubuntu Server 上无头运行 Chromedriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Java (1.8) 中使用 Selenium 和 Chromedriver 来做一些自动网络爬取:

                  I am using Selenium with Chromedriver in Java (1.8) to do some automated web crawling:

                  System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
                  WebDriver driver = new ChromeDriver();
                  driver.get("someurl.com");
                  

                  我正在尝试迁移到 Ubuntu 16.04 服务器.在服务器上,我安装了 Ubuntu chromedriver 2.37 版、chrome 65 版.根据 chromedriver 文档,这些版本是兼容的.我已经更改了指定 Ubuntu 中 chromedriver 位置的代码:

                  I am attempting to migrate to an Ubuntu 16.04 Server. On the server I have installed the Ubuntu chromedriver version 2.37, chrome version 65. According to the chromedriver documentation these versions are compatible. I have changed the code specifying the location of the chromedriver in Ubuntu:

                  System.setProperty("webdriver.chrome.driver", "/usr/lib/local/chromedriver");
                  

                  在运行我的程序之前,我启动了 xvfb:

                  Prior to running my program I start up xvfb:

                  Xvfb -ac :99 -screen 0 1280x1024x16 &
                  export DISPLAY=:99
                  

                  然后执行我的程序:

                  java -jar myprogram.jar
                  

                  以下内容打印到控制台:

                  The following is printed to the console:

                  Starting ChromeDriver 2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7) on port 10574
                  Only local connections are allowed.
                  Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
                    (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.4.0-112-generic x86_64) (WARNING: The server did not provide any stacktrace information)
                  Command duration or timeout: 60.35 seconds
                  Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
                  System info: host: 'ubuntu-s-1vcpu-1gb-nyc1-01', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-112-generic', java.version: '1.8.0_151'
                  Driver info: driver.version: ChromeDriver
                          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
                          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                          at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                          at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
                          at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
                          at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
                          at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
                          at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
                          at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
                          at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
                          at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
                          at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
                          at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
                          at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
                          at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
                          at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
                          at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
                          at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
                          at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
                          at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
                          at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
                          at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
                          at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
                          at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
                          at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
                          at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
                          at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
                          at RHio.Test.main(Test.java:39)
                  

                  推荐答案

                  这个错误确实让我们知道发生了什么错误:

                  The error does gives us some idea about whats wrong happening :

                  Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
                  

                  当您尝试在 Ubuntu Server headless 上启动 ChromedriverChrome 时,您必须通过几个选项如下:

                  As you are trying to initiate Chromedriver and Chrome on Ubuntu Server headless you have to pass a couple of Options as follows :

                  from selenium import webdriver
                  from selenium.webdriver.chrome.options import Options
                  
                  options = Options()
                  options.add_argument("--headless")
                  options.add_argument("--no-sandbox")
                  options.add_argument("start-maximized")
                  options.add_argument("disable-infobars")
                  options.add_argument("--disable-extensions")
                  driver = webdriver.Chrome(chrome_options=options, executable_path='/path/to/chromedriver')
                  driver.get('http://google.com/')
                  driver.quit()
                  

                  附加说明

                  根据强制性要求和#1341 确保以下内容:

                  • Chromedriver/usr/local/bin/
                  • Chrome 浏览器/usr/bin/google-chrome
                  • Chromedriver is within /usr/local/bin/
                  • Chrome Browser is within /usr/bin/google-chrome

                  沙盒的故事

                  这篇关于在 Ubuntu Server 上无头运行 Chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                      <tbody id='5ajs2'></tbody>
                  • <small id='5ajs2'></small><noframes id='5ajs2'>

                    • <i id='5ajs2'><tr id='5ajs2'><dt id='5ajs2'><q id='5ajs2'><span id='5ajs2'><b id='5ajs2'><form id='5ajs2'><ins id='5ajs2'></ins><ul id='5ajs2'></ul><sub id='5ajs2'></sub></form><legend id='5ajs2'></legend><bdo id='5ajs2'><pre id='5ajs2'><center id='5ajs2'></center></pre></bdo></b><th id='5ajs2'></th></span></q></dt></tr></i><div id='5ajs2'><tfoot id='5ajs2'></tfoot><dl id='5ajs2'><fieldset id='5ajs2'></fieldset></dl></div>
                      <legend id='5ajs2'><style id='5ajs2'><dir id='5ajs2'><q id='5ajs2'></q></dir></style></legend>

                        <tfoot id='5ajs2'></tfoot>

                            <bdo id='5ajs2'></bdo><ul id='5ajs2'></ul>