python - 在 Selenium/Python 中出错 - chromedriver 可执行文件需要在 PATH 中
问题描述
首先,我知道这个问题在这里被问了很多。只是明确表示我已经阅读了大多数接受的答案并正确执行了所有步骤,但仍然收到问题中提到的这个错误。下面是我的脚本以及所有其他信息
[我正在将 selenium 与 chromedriver 一起使用,尝试在运行 ubuntu 20 的无头模式下将它与 chromium 浏览器一起使用]
猫测试.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 测试.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
解决方案
经过几天的解决,我终于能够修复这个错误。
因此,正如我所提到的,我正在 Android Device 上运行 Prooted Ubuntu 20。现在官方 chrome webdriver 似乎不支持 linux 内核架构为 aarch64 - https://chromedriver.chromium.org
要解决此问题,只需下载为 arm64 变体编译的 chromedriver。您始终可以从此处获取最新版本 - https://github.com/electron/electron/releases
简而言之,其他一切都很完美,只需将 wget 链接替换为 - https://github.com/electron/electron/releases/download/v8.3.4/chromedriver-v8.3.4-linux-arm64.zip
PS /也许如果错误类似于-不支持linux内核架构,修复它会容易得多,但没关系。
推荐阅读
- javascript - 如何使用setformdata将数据存储在form中
- c# - 如何在 xamarin 表单中可绑定布局的数据模板选择器中获取列表大小
- ios - 如何将 BLE 设备中的十六进制数据分解为可用数据?(速度和节奏)
- c# - 查询未按预期执行,无论如何都返回 -1
- typescript - ESLINT_NO_DEV_ERRORS 标志在 Typescript 项目中不起作用
- cassandra-3.0 - 在 Cassandra 3.0 中启用查询跟踪
- javascript - 如何向 D3.js 子图添加工具提示
- spring - 如何使用springboot将十六进制值解码为二进制值?
- sql - 无法翻译 LINQ 查询
- javascript - Visual Studio Outlook 加载项调试:无模块