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. Unable to execute command or shell on remote system: Failed to Execute process

    1.问题描述 先说下我的项目环境:jenkins部署在windows下面,项目部署也是在windows下面,ssh服务器是FreeSSHd,原来是打算用Send files or execute co ...

  2. Java_Day3(下)

    Java learning_Day3(下) 本人学习视频用的是马士兵的,也在这里献上 <链接:https://pan.baidu.com/s/1qKNGJNh0GgvlJnitTJGqgA> ...

  3. Flask知识总结

    1.-----------------路由设置的2种方式----------------- 查看源码,route方法里,本质是执行app.add_url_rule() 因此可以这么写(主流方式): @ ...

  4. Codeforce 459A - Pashmak and Garden (已知两点求另外两点构成正方形)

    Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashm ...

  5. Server2012多用户远程桌面及问题解决记录

    1.开启远程桌面 转载自  https://jingyan.baidu.com/article/c275f6ba9321fda33c756712.html 2.添加用户 转载自 https://jin ...

  6. [HNOI2017] 大佬 - DP,BFS,Hash,单调性

    这真的是一道综合题.然而感觉A得莫名其妙,交上去的时候其实非常虚,然后就莫名其妙地AC了? 首先我们考虑到,所有和怼有关的操作都是时刻无关的.也就是说,我们把这些操作拆散放到任何时候都对结果不会有影响 ...

  7. Java代码手段防止非法请求——防盗链

    Java代码手段防止非法请求,思路如下:        1. 获取到当前请求的域名,如www.a.com        2. 获取到请求资源的上一个地址        3. 判断上一个地址是否为空,如 ...

  8. Attention machenism

    from attention mechanism Attention is one component of a network’s architecture, and is in charge of ...

  9. TD - 输入框

    模板1:TD - 普通输入框 <input dojoType="bootstrap.form.ValidationTextBox" dojoAttachPoint=" ...

  10. Selenium原理

      from selenium import webdriver:导入webdriver模块 当导入webdriver模块时,会执行\selenium\webdriver目录下的__init__.py ...