selenium+CentOS+Chrome

Chromedriver 肯定是要使用Chrome的 在注册文件中写下下载地址:

 vim /etc/yum.repos.d/google.repo: 

  [google]name=Google-x86_64baseurl=http://dl.google.com/linux/rpm/stable/x86_64enabled=1gpgcheck=0gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

然后下载安装:yum install google-chrome-stable

安装xvfb驱动:

yum update

yum install Xvfb

yum -install libXfont

yum install xorg-x11-fonts*

 

接着安装chromedriver:

最好在本地下载好用rz传输到云端 网址 https://chromedriver.storage.googleapis.com/index.html?path=2.44/

将文件放在PATH目录下 比如/usr/bin

具体PATH目录可以使用 echo $PATH查询,临时变量的插入(只在当前命令行有效):export PATH=$PATH:/your/path/to/dir

python测试文件:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument(‘–headless’) 
options.add_argument(‘–disable-gpu’) 
options.add_argument(‘–no-sandbox’) 
driver = webdriver.Chrome(chrome_options=options) 
driver.get(“https://www.baidu.com“) 
print(driver.page_source) 
driver.quit()

  

 

posted on 2018-11-24 12:22  batt1ebear  阅读(519)  评论(0)    收藏  举报

导航