博客
关于我
CentOS + Selenium+Chrome环境安装
阅读量:364 次
发布时间:2019-03-04

本文共 928 字,大约阅读时间需要 3 分钟。

# 以Chrome为例# 安装seleniumpip3 install selenium# 安装chrome-browserwget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --no-check-certificate  sudo yum install google-chrome-stable_current_x86_64.rpm# 安装chromedriver:一个用来和chrome交互的接口sudo yum install chromedriver# 编写test.py文件vim test.py

安装这个的时候  google-chrome-stable_current_x86_64 有一个y/d/N 选y

# test.pyfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument('--headless') # 16年之后,chrome给出的解决办法,抢了PhantomJS饭碗chrome_options.add_argument('--disable-gpu')chrome_options.add_argument('--no-sandbox')  # root用户不加这条会无法运行driver = webdriver.Chrome(chrome_options=chrome_options)for i in range(10):    driver.get("https://www.baidu.com/")    print(driver.title)driver.close()# 正常的输出就是10个"百度一下,你就知道"

为毛 要使用chrome_options这个参数呢。。因为centos没有图形化界面  所以只能用无参数来执行。

无参数的好处就是隐形执行。坏处就是需要对协议有更深层的了解。

转载地址:http://uxtr.baihongyu.com/

你可能感兴趣的文章
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>
mysql中的四大运算符种类汇总20多项,用了三天三夜来整理的,还不赶快收藏
查看>>
mysql中的字段如何选择合适的数据类型呢?
查看>>
MySQL中的字符集陷阱:为何避免使用UTF-8
查看>>
mysql中的数据导入与导出
查看>>
MySQL中的时间函数
查看>>
mysql中的约束
查看>>
MySQL中的表是什么?
查看>>
mysql中穿件函数时候delimiter的用法
查看>>
Mysql中索引的分类、增删改查与存储引擎对应关系
查看>>
Mysql中索引的最左前缀原则图文剖析(全)
查看>>