問題描述
我想在我的服務(wù)器上使用 selenium 構(gòu)建我的爬蟲.
I'd like to construct my crawler using selenium on my server.
因此我已經(jīng)在我的 Ubuntu17.10 服務(wù)器上安裝/下載了所需的依賴項(xiàng),例如 chromedriver、chromium-browser 等
Thus I had installed/download required dependencies- such as chromedriver, chromium-browser etc on my Ubuntu17.10 server
但是,當(dāng)我運(yùn)行以下代碼時(shí):
However, when I run following code:
driver = webdriver.Chrome()
它返回以下錯(cuò)誤:
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-14-2cdab8938403> in <module>()
----> 1 driver = webdriver.Chrome()
/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options)
66 service_args=service_args,
67 log_path=service_log_path)
---> 68 self.service.start()
69
70 try:
/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
96 count = 0
97 while True:
---> 98 self.assert_process_still_running()
99 if self.is_connectable():
100 break
/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
109 raise WebDriverException(
110 'Service %s unexpectedly exited. Status code was: %s'
--> 111 % (self.path, return_code)
112 )
113
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
興奮是什么意思..?
我不知道那個(gè)錯(cuò)誤代碼的初衷是什么,從哪里開始修復(fù)它.
I can't get what the original intention of that error code and where to start to fix it.
這看起來非常罕見.
可能相關(guān):
我已經(jīng)在我的桌面上安裝了 ubuntu desktop 17.10,但未能獲得 GUI 啟動.因此我只使用終端,但到目前為止效果很好.我已經(jīng)將 ssh 和遠(yuǎn)程控制 jupyter notebook 從我的 mac 安裝到服務(wù)器桌面,而這些錯(cuò)誤來自它.希望此信息與解決此錯(cuò)誤相關(guān),否則將中止它.
I had install ubuntu desktop 17.10 on my desktop but failed to get GUI boot. Thus I am just using terminal only, but it well works so far. I had installed ssh and remote controlling jupyter notebook from my mac to server desktop, and those errors comes from it. Hope this info is relevant to solve this error, otherwise will abort it.
推薦答案
看來 chromedriver
需要一些額外的庫.這為我解決了這個(gè)問題:
It seems chromedriver
needs some extra libraries. This solved the issue for me:
apt-get install -y libglib2.0-0=2.50.3-2
libnss3=2:3.26.2-1.1+deb9u1
libgconf-2-4=3.2.6-4+b1
libfontconfig1=2.11.0-6.7+b1
我正在使用 docker 容器而不是沒有 X/GUI 的服務(wù)器/VM 進(jìn)行類似的設(shè)置.
I was working on a similar setup using a docker container instead of a server/VM without X / GUI.
為了弄清楚需要哪些依賴項(xiàng),我反復(fù)嘗試從命令行運(yùn)行它,如下所示:/opt/chromedriver/2.33/chromedriver --version
一遍又一遍.
To figure out which dependencies are required I tried iteratively to run it from the command line like this: /opt/chromedriver/2.33/chromedriver --version
over and over again.
然后我每次都使用 apt-cache search <STUFF>
和 apt-cache madison <STUFF>
等命令來找出確切的版本chromedriver
2.33 所需的 deb
包(在我的情況下,但我想類似的東西適用于任何版本的 chromedriver
).
Then at eache time I used commands like apt-cache search <STUFF>
and apt-cache madison <STUFF>
to figure out the exact version of the deb
package needed by chromedriver
2.33 (in my case, but I guess something similar would work for any version of chromedriver
).
編輯
正如評論中所建議的,使用 ldd
命令打印共享對象依賴關(guān)系可能是另一種選擇.到今天為止,我的 chromedriver
版本在原始答案幾年后是 83.0.4103.14
- 依賴項(xiàng)也不同,但請參閱下文以了解可能發(fā)生的情況失蹤:
As suggested in the comments, using the ldd
command to print shared object dependencies may be another option. As of today my chromedriver
version after a few years from the original answer is 83.0.4103.14
- the dependencies are different as well, but see below to get an idea of what could be missing:
$ /usr/local/bin/chromedriver --version
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119})
$ ldd /usr/local/bin/chromedriver
linux-vdso.so.1 (0x00007fffff7f0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f414739d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f414737a000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f414736f000)
libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f4147246000)
libnss3.so => /usr/lib/x86_64-linux-gnu/libnss3.so (0x00007f41470f7000)
libnssutil3.so => /usr/lib/x86_64-linux-gnu/libnssutil3.so (0x00007f41470c4000)
libnspr4.so => /usr/lib/x86_64-linux-gnu/libnspr4.so (0x00007f4147082000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f4146f45000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4146df6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4146ddb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4146be9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4147e56000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f4146b76000)
libplc4.so => /usr/lib/x86_64-linux-gnu/libplc4.so (0x00007f4146b6d000)
libplds4.so => /usr/lib/x86_64-linux-gnu/libplds4.so (0x00007f4146b68000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f4146b3e000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f4146b38000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f4146b30000)
libbsd.so.0 => /usr/lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f4146b14000)
來自man ldd
:
ldd 打印命令行指定的每個(gè)程序或共享對象所需的共享對象(共享庫).
ldd prints the shared objects (shared libraries) required by each program or shared object specified on the command line.
...
在通常情況下,ldd 調(diào)用標(biāo)準(zhǔn)動態(tài)鏈接器(參見 ld.so(8))將 LD_TRACE_LOADED_OBJECTS 環(huán)境變量設(shè)置為 1.這使動態(tài)鏈接器檢查程序的動態(tài)依賴項(xiàng),并查找(根據(jù) ld.so(8) 中描述的規(guī)則)并加載滿足這些依賴關(guān)系的對象.對于每個(gè)依賴關(guān)系,ldd 顯示匹配對象的位置和(十六進(jìn)制)加載它的地址.
In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1. This causes the dynamic linker to inspect the program's dynamic dependencies, and find (according to the rules described in ld.so(8)) and load the objects that satisfy those dependencies. For each dependency, ldd displays the location of the matching object and the (hexadecimal) address at which it is loaded.
這篇關(guān)于WebDriverException:消息:服務(wù) chromedriver 意外退出.狀態(tài)碼是:127的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!