简体   繁体   English

在 raspberry Pi 3 上使用带有 chromedriver 的 selenium 时出错 - Raspbian Jessie

[英]Error using selenium with chromedriver on raspberry Pi 3 - Raspbian Jessie

I try to execute this ::我尝试执行这个::

from selenium import webdriver
import time
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import schedule
from datetime import datetime

driver = webdriver.Chrome('/home/pi/Documents/chromedriver')
driver.get('http://google.com')
time.sleep(5)

Here is the error I get :这是我得到的错误:

Traceback (most recent call last):
  File "test2.py", line 12, in <module>
    driver = webdriver.Chrome('/home/pi/Documents/chromedriver')  # Optional arg$
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error

Is there anybody who know how to solve it ?有没有人知道如何解决它? I tried also with firefox and xvfb with no success for the moment.我也尝试过 firefox 和 xvfb,但暂时没有成功。

Here is the path define in '.bashrc' :这是在 '.bashrc' 中定义的路径:

export $PATH=$PATH:/home/pi/Documents/chromedriver

Not sure if this will help you, but I set up my selenium environment on my Ubuntu machines (raspberry pi should be similar enough) using this helper script.不确定这是否会帮助你,但我使用这个帮助脚本在我的 Ubuntu 机器上设置了我的 selenium 环境(树莓派应该足够相似)。 Install setupdriver.sh安装 setupdriver.sh

echo "removing chromium-browser"
sudo apt-get purge chromium-browser
rm ~/.config/chromium/ -rf
echo "removing chrome"
sudo apt-get purge google-chrome-stable
rm ~/.config/google-chrome/ -rf
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
echo "installing Chrome"
echo "getting libxi6"
sudo apt-get install libxi6 libgconf-2-4
echo "getting chromedriver2.27"
wget -N https://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip
echo "unzipping chromedriver2.27"
unzip chromedriver_linux64.zip
echo "exe chromedriver"
chmod +x chromedriver
echo "removing /usr/local/share/chromedriver"
sudo rm -rf /usr/local/share/chromedriver
echo "removing /usr/local/bin/chromedriver"
sudo rm -rf /usr/local/bin/chromedriver
echo "removing /usr/bin/chromedriver"
sudo rm -rf /usr/bin/chromedriver
echo "moving chromedriver to local/share"
sudo mv -f chromedriver /usr/local/share/chromedriver
echo "linking to bin"
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
echo "linking to local bin"
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

so try copying that code into a shell file.所以尝试将该代码复制到 shell 文件中。 chmod +x the file, then sh filename.sh or you can copy type each step directly into terminal. chmod +x文件,然后sh filename.sh或者您可以将每个步骤直接复制到终端中。

I referred to this question on reddit Success: How to run Selenium Chrome webdriver on Raspberry pi and through the comments I saw this explanation that turned out to install chromium-chromedriver properly and solved my issue. 我在reddit 成功案例中提到了这个问题:如何在Raspberry pi上运行Selenium Chrome webdriver ,通过评论,我看到了这一解释,结果证明正确安装了chromium-chromedriver并解决了我的问题。

by this code sudo apt-get install chromium-driver @vladoportos. 通过此代码sudo apt-get install chromium-driver Chrome sudo apt-get install chromium-driver @vladoportos。

Oh and it might be useful if you check the python version(update). 哦,如果您检查python版本(更新),这可能会很有用。

Based on this post, the command to install chromedriver is the follwing:根据这篇文章, 安装 chromedriver 的命令如下

sudo apt-get install chromium-chromedriver

and you will have 74.0.3729.157 version of ChromeDriver available in the system.并且您将在系统中使用 74.0.3729.157 版本的 ChromeDriver。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Raspberry Pi 4 上使用 Chromedriver 运行 Selenium 时出现问题 - Issues running Selenium with Chromedriver on Raspberry Pi 4 树莓派 selenium chromedriver "/usr/bin/chromedriver: 5: 语法错误: word unexpected (expecting ")")" - Raspberry Pi selenium chromedriver "/usr/bin/chromedriver: 5: Syntax error: word unexpected (expecting ")")" 在带有铬的Raspberry Pi上使用硒 - Using Selenium on Raspberry Pi with Chromium 在 Raspberry Pi 上使用 Selenium headless - Using Selenium on Raspberry Pi headless Raspbian(Raspberry pi)的Google Speech Api凭据错误 - Google Speech Api Credential Error with Raspbian (Raspberry pi) 在我的覆盆子pi上运行无头chromedriver时,Selenium崩溃了 - Selenium crashing when running headless chromedriver on my raspberry pi 使用Raspbian和Raspberry Pi将运动文件上传到Google云端硬盘 - Uploading Motion Files to Google Drive using Raspbian and Raspberry Pi 在树莓派上使用Selenium和Python登录zoom时出现401错误 - Error 401 while using Selenium and Python to log into zoom on Raspberry Pi WebDriverException:消息:服务 /usr/lib/chromium-browser/chromedriver 在 Raspberry-Pi 和 Selenium 上意外退出 - WebDriverException: Message: Service /usr/lib/chromium-browser/chromedriver unexpectedly exited on Raspberry-Pi with ChromeDriver and Selenium python wavebender模块树莓派树莓派 - python wavebender module raspberry pi raspbian
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM