2017-02-03 8 views
0

Linuxでウェブドライバを起動しようとすると、少し時間がかかります。Linux上のSelenium Chrome Driver

私はCentOS 7.3です。Chrome、ChromiumなどのPythonライブラリをインストールしました。私は走っています:

chrome_options = webdriver.ChromeOptions() 
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options) 

別のパスを使って、別のパスがWindows上でうまく動作するので、問題はLinuxへの私のポートには間違いありません。

私が走ってきました:

chmod a+x chromedriver 

をそして、それはchromedriverへのアクセス権を持っている必要がありますので、それはルートの下で実行されます。

タイムアウトを指定してスレッドプールを介してスレッドを生成すると、そのタイムアウトが毎回発生します。それを実行する場合には、通常、それが最終的にエラーがスローされます:私は上に行くために多くを与えない:ここ

Traceback (most recent call last): 
    File "Skyscrapercomp.py", line 492, in <module> 
    thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__ 
    desired_capabilities=desired_capabilities) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session 
    response = self.execute(Command.NEW_SESSION, capabilities) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally 
    (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.10.0-514.2.2.el7.x86_64 x86_64) 

私のお持ち帰りは「異常終了したChromeは起動に失敗しました」でした。

私はpipを使ってChromiumとChromeをインストールするために最新のSeleniumとYumをインストールしました。私の次のステップが何であるかわからない水の中で少し死んだと感じるので、私は正しい方向にプロダクトを本当に感謝します。

/更新:

Iは、/ usr/binにグーグル・クロームでチェック、それは望んでいるデフォルトの場所であるがあります。

はまた、それに場所を与えては/ usr/binとないにchromedriverを入れてみました:

TheBrowser = webdriver.Chrome() 
TheBrowser.get("http://www.google.com") 
print TheBrowser.page_source.encode('utf-8') 

しかし、これは同じエラーを与えます。

+0

あなたは対話的に実行しようとしていますか、またはxvfbをセットアップしましたか? –

+0

セレンがアクセスできる限り、私には関係ありません。私はxvfbをセットアップしてそのようにします。 – PoweredByCoffee

+0

問題がある可能性があります。ディスプレイがない場合、Chromeドライバはそのように失敗します。そう、はい、適切なxvfbソリューションを設定してみてください。少なくとも、このエラーの一般的な原因の1つを排除します。 –

答えて

0

は、問題を見つけるためにログを使用するようにしてください:

chrome_options = webdriver.ChromeOptions() 
service_log_path = 'chromedriver.log' 
service_args = ['--verbose'] 

thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options, service_args=service_args, service_log_path=service_log_path) 

私の場合は、エラーが表示(なしX11私のUbuntuのサーバー上)でした。これは私を助けました:

from pyvirtualdisplay import Display 
display = Display(visible=0, size=(800, 600)) 
display.start() # don't forget to .stop() it at the end of program 
関連する問題