我想在我的服务器上使用 selenium 构建我的爬虫。
因此我已经在我的 Ubuntu17.10 服务器上安装/下载了所需的依赖项——例如 chromedriver、chromium-browser 等
但是,当我运行以下代码时:
driver = webdriver.Chrome()
它返回以下错误:
---------------------------------------------------------------------------
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
它很兴奋..是什么意思?
我不明白该错误代码的初衷是什么以及从哪里开始修复它。
这看起来非常罕见。
可能相关:
我在我的桌面上安装了 ubuntu desktop 17.10,但无法获得 GUI 启动。因此我只使用终端,但到目前为止效果很好。 我已经从我的 mac 到服务器桌面安装了 ssh 和远程控制 jupyter 笔记本,这些错误来自它。 希望此信息与解决此错误相关,否则将中止。
最佳答案
好像chromedriver
需要一些额外的库。这为我解决了这个问题:
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 的服务器/VM 进行类似的设置。
为了确定需要哪些依赖项,我尝试从命令行反复运行它,如下所示:/opt/chromedriver/2.33/chromedriver --version
一遍又一遍。
然后每次我都使用像 apt-cache search <STUFF>
这样的命令和 apt-cache madison <STUFF>
找出 deb
的确切版本chromedriver
需要的包2.33(就我而言,但我想类似的东西适用于 chromedriver
的任何版本)。
编辑
如评论中所建议,使用 ldd
打印共享对象依赖项的命令可能是另一种选择。截至今天我的chromedriver
原始答案几年后的版本是83.0.4103.14
- 依赖关系也不同,但请参阅下文以了解可能缺少的内容:
$ /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 prints the shared objects (shared libraries) required by each program or shared object specified on the command line.
...
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.
关于python - WebDriverException : Message: Service chromedriver unexpectedly exited. 状态代码为:127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49323099/