1. 程式人生 > >python 頁面點選事件實現selenium

python 頁面點選事件實現selenium

pip install selenium

# coding=utf-8
 
from selenium import webdriver
 
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://news.baidu.com')
driver.implicitly_wait(8)
 
for i in driver.find_elements_by_xpath("//*/input[@type='radio']"):
    i.click()

報錯資訊

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

解決
安裝 chromedriver

wget -N http://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

安裝chrome

yum search chrome
sudo yum -y install xorg-x11-drv-openchrome.x86_64

報錯:

selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/chromedriver unexpectedly exited. Status code was: 1

待解決