在centos7 上安裝chrome+chromedriver


安裝chrome
首先安裝google的epel源
vi /etc/yum.repos.d/google.repo
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64 

enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub 


yum update , 然后yum install google-chrome-stable
chromedriver下載
https://npm.taobao.org/mirrors/chromedriver/ 

 將下載的chromedriver 放到腳本同級目錄調用
3.安裝selenium,使用是的python3
pip3 install selenium 
默認centos 7已經安裝了python2,指定python3安裝selenium可以指定bin目錄下的pip來安裝
代碼測試:
以登陸西部數碼為例
#!/usr/local/python3/bin/python3

from selenium import webdriver
from selenium.webdriver.chrome.options import Options



chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
url="https://www.west.cn/login.asp 

"
brower=webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
brower.get(url)
name=brower.find_element_by_xpath('//input[@name="u_name"]')
name.send_keys('******')
mima=brower.find_element_by_xpath('//input[@name="u_password"]')
mima.send_keys('******')
button=brower.find_element_by_xpath('//button[@class="g-commo"]')
button.click()
brower.refresh()
brower.get("https://www.west.cn/Manager/")
brower.quit()

 linux查看谷歌版本:/usr/bin/google-chrome -version


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM