美文网首页
Centos7 Dos下运行chrome headless

Centos7 Dos下运行chrome headless

作者: 周末的游戏之旅 | 来源:发表于2019-12-15 20:14 被阅读0次

安装chrome

1.配置yum源,使用root账户

cd /etc/yum.repos.d/
vi google-chrome.repo

将下面内容写入文件

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

2.安装

yum -y install google-chrome-stable --nogpgcheck

3.验证

[root@localhost yum.repos.d]# google-chrome -version
Google Chrome 64.0.3282.140

安装chromedriver

1.下载chromedriver

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

国内可从 https://npm.taobao.org/mirrors/chromedriver下载
2.将下载的文件解压至 /usr/bin/ 目录下

  1. 运行脚本
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('headless')
# 非安全模式下运行,若脚本运行报错,需要加上这一个参数
option.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=option)
driver.get("http://www.baidu.com")
print(driver.title)
driver.quit()

相关文章

网友评论

      本文标题:Centos7 Dos下运行chrome headless

      本文链接:https://www.haomeiwen.com/subject/isslnctx.html