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. css页面字体替换源代码和页面显示不一样问题解决

    2018年8月27日19:58:12 css指定字体的时候,可以自制的字体,比如字符替换,比如 0没有被替换,其他在源代码被替换对应的字母,但是现实的时候在替换成正确的数字 很简单,防爬虫,但是... ...

  2. 换目标啦,初识PHP

    一.初识PHP脚步程序 1.PHP开始标记 <?php 2.PHP结束标记 ?> <?php?> 3.我们的页面最终是通过html,css,js来展示出一个炫丽的界面 4.PH ...

  3. pycharm 的 激活流程

    激活流程 一.通过Activation code 方式激活 注册码获取地址为:http://idea.lanyus.com/ 在idea或者pycharm的Activation code中输入 注册码 ...

  4. SaaS的先鋒:多合一讯息处理器

    在Rocketbots,我们的使命是改善企业与客户之间的关係.全球有超过40亿个消息传递帐户,人们花在上线对话的时间比任何其他活动都多.这种转变,创造了一个更高效及贴身的沟通.随著消费者越来越多要求, ...

  5. 遍历其 interator

    当用户自定义数据结构的时候, 如果做遍历呢, 这个时候就需要遍历器 interator 了, 它允许用户定义遍历自己自定义数据结构的方式 当用户定义了iterator, 就可以使用 for of 来遍 ...

  6. RuntimeError: implement_array_function method already has a docstring

    根源:Numpy/Scipy/Pandas/Matplotlib/Scikit-learn 出现冲突 解决办法: pip uninstall scikit-learn pip uninstall ma ...

  7. linux和shell的学习记录

    1.16条常用的命令 .文件的权限修改:(把文件1.txt的归属改为mysql的,然后ll查看) chown mysql:mysql .txt .增加当前用户的x权限,然后ll查看: chomd u+ ...

  8. (李南江jQuery+Ajax)第一章:初识jQuery

    第一章:初识jQuery 一.原生的JS与jQuery的区别 <!DOCTYPE html> <html lang="en"> <head> & ...

  9. 用vue怎么写点击保存之后的返回的代码?

    点击完保存调用接口之后,如果使用  this.$router.go(-1); 返回到编辑页面,数据不会有更新,使用 this.$router.replace({ name: '信息展示', param ...

  10. Python3学习之路~7.3 反射

    python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,该四个函数分别用于对对象内部执行:检查是否含有某成员.获取成员.设置成员.删除成员. ...