+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

在Selenium / Python中出现错误-chromedriver可执行文件必须位于PATH中

发布于2020-07-13 05:20     阅读(1121)     评论(0)     点赞(11)     收藏(0)


首先,我知道这个问题在这里已经被问了很多了。请明确说明我已阅读了大多数接受的答案,并正确地执行了所有步骤,仍然遇到了所提到的错误。以下是我的脚本以及所有其他信息

[我在chromedriver中使用硒,试图在无头模式下运行ubuntu 20的铬浏览器中使用它]

猫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


解决方案


经过数天的努力,我终于能够解决此错误。

因此,正如我之前提到的,我正在Android Device上运行Prooted Ubuntu 20。现在,这里的Linux内核架构之中aarch64似乎不是由官方Chrome支持的webdriver - 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内核体系结构,则修复它会容易得多,但是没关系。



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/442668/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

11 0
收藏该文
已收藏

评论内容:(最多支持255个字符)