安装chrome首先安装google的epel源vi /etc/yum.repos.d/google.repo[google]name=Google-x86_64baseurl=http://dl.google.com/linux/rpm/stable/x86_64 enabled=1gpgcheck=0gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub yum update , 然后yum install google-chrome-stablechromedriver下载https://npm.taobao.org/mirrors/chromedriver/ 将下载的chromedriver 放到脚本同级目录调用3.安装selenium,使用是的python3pip3 install selenium 默认centos 7已经安装了python2,指定python3安装selenium可以指定bin目录下的pip来安装代码测试:以登陆西部数码为例#!/usr/local/python3/bin/python3from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_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