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:

扫描二维码关注公众号,回复: 4207027 查看本文章

最好在本地下载好用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()

  

猜你喜欢

转载自www.cnblogs.com/batt1ebear/p/10011629.html