【发布时间】:2020-10-13 09:01:24
【问题描述】:
首先,我知道这个问题在这里被问了很多。只是明确表示我已经阅读了大多数接受的答案并正确执行了所有步骤,但仍然收到问题中提到的这个错误。 下面是我的脚本以及所有其他信息
[我正在使用 selenium 和 chromedriver,试图在运行 ubuntu 20 的无头模式下将它与 chromium 浏览器一起使用]
cat test.py
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.binary_location = '/usr/bin/chromium-browser'
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
driver.get("https://www.google.com")
print(driver.title)
print ("Headless Chrome Initialized")
driver.quit()
python3 test.py
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 9, in <module>
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我遵循了哪些步骤
sudo apt install chromium-browser
python3 -m pip install selenium
wget https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip
unzip chromedriver*
chmod +x chromedriver
sudo mv chromedriver /usr/local/bin/
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
一起验证一切
╭─[localhost] as xd003 in ~
╰─➤ lsb_release -a | grep Description && \
apt -qq list python3 && \
apt -qq list chromium-browser && \
which chromedriver && \
which chromium-browser && \
echo $PATH
No LSB modules are available.
Description: Ubuntu 20.04 LTS
python3/focal,now 3.8.2-0ubuntu2 arm64 [installed]
chromium-browser/focal-updates,now 81.0.4044.129-0ubuntu0.20.04.1 arm64 [installed]
/usr/local/bin/chromedriver
/usr/bin/chromium-browser
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
一切看起来都不错,有人可以建议我做错了什么吗?
我在本地运行的 Ubuntu20 是我在我的 android 设备上使用的 Ubuntu Proot
【问题讨论】:
-
我已经在那里阅读了接受的答案,唯一不同的是这一步 - export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step ...而不是这个我做了 sudo mv geckodriver /usr/local/bin/ 虽然理想情况下这应该绝对有效
-
我没有意识到你明确地将
/usr/local/bin/geckodriver路径作为参数,我的错。 -
我看到你做了一个
chmod +x,你确定是同一个用户在运行 Python 脚本吗? -
@Arount 是的,我是唯一的用户
标签: python python-3.x selenium selenium-webdriver selenium-chromedriver