Ubuntu 16.04 下:

0x01 安装chrome

1 下载源加入系统源列表

sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/
 

2 导入google软件公钥

wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
 

3 更新源

sudo apt-get update
 

4 安装chrome

sudo apt-get install google-chrome-stable
 

5 查看安装路径

cd /usr/bin/
 
xxaq@xxaq-System-Product-Name-Invalid-entry-length-16-Fixed-up-to-11:/usr/bin$ ll google*
lrwxrwxrwx 1 root root 31 2月  24 08:59 google-chrome -> /etc/alternatives/google-chrome*
lrwxrwxrwx 1 root root 32 2月  22 11:06 google-chrome-stable -> /opt/google/chrome/google-chrome*
 

6 查看安装版本

xxaq@xxaq-System-Product-Name-Invalid-entry-length-16-Fixed-up-to-11:/usr/bin$ google-chrome --version
Google Chrome 64.0.3282.186
 

7 google-chrome运行报错

xxaq@xxaq-System-Product-Name-Invalid-entry-length-16-Fixed-up-to-11:~$ google-chrome --headless http://www.baidu.com
[0224/090953.953883:ERROR:instance.cc(49)] Unable to locate service manifest for metrics
[0224/090953.954581:ERROR:service_manager.cc(890)] Failed to resolve service name: metrics
[0224/090953.957121:FATAL:nss_util.cc(631)] NSS_VersionCheck("3.26") failed. NSS >= 3.26 is required. Please upgrade to the latest NSS, and if you still get this error, contact your distribution maintainer.
已放弃 (核心已转储)
[0100/000000.152280:ERROR:broker_posix.cc(43)] Invalid node channel message
 
原因:nss版本需要更新
 
解决方法:
sudo apt install --reinstall libnss3
 

0x02 安装chromedriver

1 下载地址:

下载chrome版本对应的chromedriver
对照表网上有人整理,也可以看http://chromedriver.storage.googleapis.com/index.html 下面各个版本里的note文件:
其中chrome 64对应的是2.35版本

2 配置 :

对下载的zip文件直接unzip
unzip chromedriver_linux64.zip
拷贝到/usr/bin/下面
sudo cp chromedriver /usr/bin/
 

0x03 Python下的调用

1  安装 selenium

sudo pip install selenium

2 测试demo

#encoding: utf-8

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
#chrome_options.add_argument('--disable-gpu') chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chromedriver)
#driver = webdriver.Chrome(executable_path=chromedriver)
driver.get("https://stackoverflow.com")
print driver.page_source
driver.save_screenshot('screen.png')
driver.quit()

CentOS7 下:

安装,chrome,chromedriver原理同上

注意在使用的时候要加上

chrome_options.add_argument("--no-sandbox")

否则会出现报错

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 3.10.0-693.el7.x86_64 x86_64)

原因:

谷歌浏览器报错:请以普通用户的身份启动Google Chrome。如果您出于开发目的,需要以根用户打身份运行Chrome,请使用-no-sandbox标记重新运行Chrome

ubuntu没有报错是因为不是以root用户登录的。

测试demo:

#encoding: utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
#chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("--no-sandbox") chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chromedriver)
#driver = webdriver.Chrome(executable_path=chromedriver)
driver.get("https://stackoverflow.com")
print driver.page_source
driver.save_screenshot('screen.png')
driver.quit()

chrome headless+selenium+python+(ubuntu 16.04/centos7) 下的实现的更多相关文章

  1. 在Ubuntu 16.04 LTS下编译安装OpenCV 4.1.1

    目录 一 安装前的准备 二 编译并安装OpenCV 4.1.1 注:原创不易,转载请务必注明原作者和出处,感谢支持! OpenCV目前(2019-8-1)的最新版本为4.1.1.本文将介绍如何在Ubu ...

  2. Ubuntu 16.04系统下安装Discuz出现“HTTP ERROR 500”目前无法处理此请求

    问题:当我们在Ubuntu 16.04系统下安装Disucz X3时,修改好文件的权限,浏览器输入地址安装时出现如下图所示问题: 问题查询: 在终端输入: tail -f /var/log/apach ...

  3. Ubuntu 16.04.5下FFmpeg编译与开发环境搭建

    PC环境: Ubuntu 18.04 上面只要安装下面的提示安装即可,基本上不必再下载依赖库的源代码进行编译和安装 编译步骤: 1, 安装相关工具: sudo apt  install -y auto ...

  4. Ubuntu 16.04.4下安装apache服务

     Ubuntu 16.04.4下安装apache服务: 一.首先,准备需要的预装环境 需要c++,make,gcc,apr  apr-util  pcre.(如果后面报错缺少什么组件,可以百度搜方法. ...

  5. Ubuntu 16.04系统下安装PHP5.6*

    Ubuntu 16.04系统默认php7,并没有php5*的包,所以需要自己安装: 方法: 1.删除所有的php包列出安装的php包,dpkg -l | grep php| awk '{print $ ...

  6. kettle的下载、安装和初步使用(Ubuntu 16.04平台下)(图文详解)

    不多说,直接上干货! 能够看我这篇博客的博友们,想必是已经具备一定基础了. 扩展博客 kettle的下载.安装和初步使用(windows平台下)(图文详解) kettle的下载 žKettle可以在h ...

  7. Ubuntu 16.04 LTS 下安装MATLAB2015b 以及Matlab system error解决办法

    下载MATLAB2015b破解版 操作系统:Ubuntu 16.o4 LTS 程序文件:Matlab2015b-glnxa64破解版 解压提取文件:在ubuntu系统下可以直接提取压缩文件,得到三个文 ...

  8. Ubuntu 16.04安装下HTK--亲测ok

    1.首先需要安装一些32位库sudo apt-get install libx11-dev:i386 libx11-dev sudo apt-get install g++-multilib sudo ...

  9. 解决Ubuntu 16.04 环境下Python 无法显示中文的问题

    一.下载中文字体(https://pan.baidu.com/s/1EqabwENMxR2WJrHfKvyrIw 这里下载多是SImhei字体) 安装字体:解压:unzip SimHei.zip拷贝字 ...

随机推荐

  1. 百度地图根据list经纬度算每个点到剩余点的平均距离、最远距离和最近距离

    一.使用步骤 说明:给你一大串坐标list.计算每个点到其他所有点的最近最远平均距离. 1.打开百度地图api在线demo(随便一个都行) 2.替换<script></script& ...

  2. java中给集合快速取值最大值和最小值

    public static void main(String[] args) { List list = new ArrayList(); list.add(new Double(123.23)); ...

  3. IDEA常用的几个插件

    目录 1. 阿里巴巴代码检测插件 2. Json转Pojo插件 3. mybatis辅助插件 4. 翻译插件 5. markdown插件 6. RestfulToolKit插件 IDEA常用插件 1. ...

  4. Codeforces 577A - Multiplication Table

    Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i ...

  5. Qt Gui 第一章~第二章

    一.Qt启动 qmake -project; 创建xxx.pro qmake xxx.pro; 生成makefile文件 make:构建该程序,生成可执行文件 运行程序:windows:xxx:mac ...

  6. 转行小白成长路--java基础

    每天都会发一篇,一点一滴,记录在这条路上的足迹.立个flag 2019年3月份至今已近一年,对信息技术有个大概的了解,个人认为对于这门技术更应该从最底层的原理入手,了解计算机演化的历史,从计算机语言到 ...

  7. SpringBoot学习- 7、问题Could not autowire. No beans of 'xxxx' type found处理

    SpringBoot学习足迹 这个问题网上有好多同学都提到这个问题,代码可以运行,但是就是有红线,强迫症不能忍 自己试验下 1.增加一个final编译一下,再删掉就不会出红线了 public clas ...

  8. model_Flask

    虚拟环境 新建一个虚拟环境:mkvirtualenv 环境名 删除一个虚拟环境:rmvirtualenv 环境名 退出:deactivate win10下安装 1. 打开cmd 安装虚拟环境包 pip ...

  9. 巨杉Tech | 使用 SequoiaDB 分布式数据库搭建JIRA流程管理系统

    介绍 JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪.项目跟踪和敏捷管理等工作领域.很多企业与互联网公司都在使用Jira作为内部 ...

  10. python接口自动化之发送post(四)

    1.ssl问题 目前很多的请求使用的都是较为安全的https请求,https请求相对于http安全级别更高,需要验证ssl证书 写代码的时候有两种可以忽略ssl验证的方法 (1)import urll ...