1. 安装 selenium : sudo pip install selenium

2. 安装 chromdriver: 进入 淘宝镜像源 下载 chromdriver, 可以查看 notes.txt 文件,看chrome 和ChromDriver 两者相对应的兼容版本

3. 下载chrome : 下载 chromedriver_linux64.zip

4. 将 chromdriver 文件放到线上服务器 /usr/bin/ 下 ,将google-chrome-stable_current_amd64.deb上传线上服务器

5. 安装chrome,执行如下命令:

sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
google-chrome --version # 查看版本

6. 编写测试脚本

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox') # 这个配置很重要
client = webdriver.Chrome(chrome_options=chrome_options, executable_path='/home/chromedriver') # 如果没有把chromedriver加入到PATH中,就需要指明路径 client.get("https://www.baidu.com")
print (client.page_source.encode('utf-8')) client.quit()

  

Ubuntu 无界面使用selenium chrome + headless的更多相关文章

  1. ubuntu中如何安装selenium+chrome(headless)无界面浏览器?

    selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...

  2. centos 无界面安装selenium+chrome+chromedirver的设置

    配了一中午的,好不容易正好记录下. 1.我的centos的位数 输入rpm -q centos-release 结果:centos-release-7-4.1708.el7.centos.x86_64 ...

  3. ubuntu服务器端使用无界面selenium+ chrome + headless

    本来想直接用Ubuntu系统里面的firefox来实现selenium自动操作签到的,但是总是出各种问题.没办法,改为Chrome.参考:Ubuntu 线上无界面服务器 使用selenium chro ...

  4. 笔记-selenium+chrome headless

    笔记-selenium+chrome headless 1.      selenium+chrome headless phantomjs与selenium分手了,建议使用其它无头浏览器. chro ...

  5. selenium chrome headless无界面引擎

    注意:PhantomJS已被舍弃 chrome headless 在打开浏览器之前添加参数 import time import sys from selenium import webdriver ...

  6. centos 无界面 服务器 安装chrome部署chromedriver

    转:https://blog.csdn.net/u013849486/article/details/79466359 基本 做完了,要弄进docker里面去了的时候,才搜到 docker-chrom ...

  7. chrome浏览器爬虫WebDriverException解决采用python + selenium + chrome + headless模式

    WebDriverException: Message: unknown error: Chrome failed to start: crashed 第一种:如果出现下面情况: chrome浏览器有 ...

  8. Selenium + Chrome headless 报ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context 可忽略并配置不输出日志

    Selenium不再推荐使用PhantomJS,会报如下警告 UserWarning: Selenium support for PhantomJS has been deprecated, plea ...

  9. selenium +chrome headless Adhoc模式渲染网页

    mannual和adhoc模式比较 Manual vs. Adhoc In the script above, we start the ChromeDriver server process whe ...

随机推荐

  1. [05-02]红帽linux常用操作命令

    命令怎么用(三种方式) shutdown --help shutdown --? man shutdown  (man 就是manual  手册, 指南) 服务 service 怎么知道服务的名字呢? ...

  2. Head First Python-python面向对象

    与大多数其他的编程语言一样,Python容许创建并定义面向对象的类,类可以将代码与代码处理的数据相关联. 对于更加复杂的数据,一般的列表已经不能满足需求了. 我们可以使用字典dict将数据值与键相关联 ...

  3. python:Crypto模块的下载

    1.下载 Crypto 用于一些加密算法,需要引入的模块 目前做支付宝接口的时候会用到 pip3 install pycryptodome # 该方式是正常的 快速方式:pip3 install -i ...

  4. 前端 CSS 介绍

    CSS介绍 我们为什么需要CSS? 使用css的目的就是让网页具有美观一致的页面,另外一个最重要的原因是内容与格式分离 在没有CSS之前,我们想要修改HTML标签的样式需要为每个HTML标签单独定义样 ...

  5. 【Linux】Set CentOS no GUI default

    [root@localhost ~]#vi /etc/inittab 重点看下面这部分代码 #   0 - halt (Do NOT set initdefault to this)          ...

  6. PrintWriter write返回数据显示中文变问号"???"

    在response.getWriter();前加上这些就ok了 response.setContentType("text/html;charset=UTF-8"); respon ...

  7. Sqlite3入门简记

    一,安装Sqlite3 1.入门时看http://www.runoob.com/sqlite/sqlite-intro.html,说的简单,但是适合入门 2.在终端输入sqlite3,没有返回信息,表 ...

  8. Leetcode Articles: Insert into a Cyclic Sorted List

    Given a node from a cyclic linked list which has been sorted, write a function to insert a value int ...

  9. hibernate连接数据库和使用

    hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibe ...

  10. 主线程 RunLoop 学习笔记

    以下为主RunLoop 的输出,能够看到不同的source0,source1,observer ---------------------------------- CFRunLoop{wakeup ...