前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos7无GUI运行selenium chromedriver 亲测可用!

centos7无GUI运行selenium chromedriver 亲测可用!

作者头像
用户1214487
发布2019-05-25 18:42:47
2.5K0
发布2019-05-25 18:42:47
举报
文章被收录于专栏:Python

1. 安装chrome

首先安装google的epel源

代码语言:javascript
复制
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

2. chromedriver下载

https://npm.taobao.org/mirrors/chromedriver/

找到chrome对应的chromedriver 版本,并下载

代码语言:javascript
复制
wget https://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip

将下载的chromedriver 放到脚本同级目录调用

3 . 为chromedriver授权

chmod 755 chromedriver

4. 测试代码 ts.py

代码语言:javascript
复制
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')    # 禁止沙箱模式,否则肯能会报错遇到chrome异常
url="https://www.west.cn/login.asp"
brower=webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
brower.get(url)
print(brower.current_url)
brower.get("https://www.west.cn/Manager/")
print(brower.current_url)
brower.quit()

5. 测试结果

参考链接:

centos 7 无gui界面运行selenium + chrome模拟登陆

在CentOS7上使用chrome(selenium)

selenium操作chrome时的一些配置

【Linux】CentOS7上解压zip需要安装uzip

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-04-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 安装chrome
  • 2. chromedriver下载
  • 3 . 为chromedriver授权
  • 4. 测试代码 ts.py
  • 5. 测试结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档