我尝试执行这个::
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)
这是我得到的错误:
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
有谁知道如何解决它? 我还尝试使用firefox和xvfb暂时没有成功。
以下是&#39; .bashrc&#39;中定义的路径:
export $PATH=$PATH:/home/pi/Documents/chromedriver
答案 0 :(得分:0)
不确定这是否会对您有所帮助,但我使用此帮助程序脚本在我的Ubuntu计算机上设置了我的selenium环境(raspberry pi应该足够相似)。安装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
所以尝试将该代码复制到shell文件中。 chmod +x
文件,然后是sh filename.sh
,或者您可以将每个步骤的类型直接复制到终端。
答案 1 :(得分:0)
我必须使用此旧版驱动程序:
https://github.com/electron/electron/releases/download/v1.6.0/chromedriver-v2.21-linux-armv7l.zip
答案 2 :(得分:0)
我在reddit Success: How to run Selenium Chrome webdriver on Raspberry pi上提到了这个问题,并通过评论看到了可以正确安装chromium-chromedriver
并解决了我的问题的解释。
通过此代码sudo apt-get install chromium-driver
@vladoportos。
哦,如果您检查python版本(更新),这可能会很有用。
答案 3 :(得分:0)