centos7 下安装chrome+chromedriver+selenium 并测试selenium运行情况

一:安装chrome  (以下是默认下载最新版)

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

二:安装chromedriver  

根据上一步安装的chrome,通过查看chrome版本,去查找相对应的chromedriver版本。

参考地址:http://chromedriver.chromium.org/downloads

这里有详细的chrome和chromedriver 版本对应关系。

比如此刻找到的对应版本的下载连接为https://chromedriver.storage.googleapis.com/2.45/chromedriver_linux64.zip

在centos上下载该zip文件。

wget  https://chromedriver.storage.googleapis.com/2.45/chromedriver_linux64.zip

三:添加Chromedriver 软链接

比如Chromedriver的位置为  /root/chromedriver   

扫描二维码关注公众号,回复: 5340751 查看本文章
ln -s /root/chromedriver /usr/bin/chromedriver

安装完成后,可保存以下py文件进行测试

在centos 上运行python + selenium +chromedriver  的一些基本操作
 

# -*- coding:utf-8 -*-

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')  # 确保无头
options.add_argument('--disable-gpu')  # 无需要gpu加速
options.add_argument('--no-sandbox')  # 无沙箱
driver = webdriver.Chrome(executable_path="/root/chromedriver", chrome_options=options)  # 添加软链接后是不需要写路径的

driver.get("https://www.baidu.com")
print(driver.page_source)
driver.quit()

猜你喜欢

转载自blog.csdn.net/xiongzaiabc/article/details/86711504