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. 使用sysbench压测磁盘io

    Ⅰ.sysbench安装 cd /usr/local/src yum -y install make automake libtool pkgconfig libaio-devel git clone ...

  2. js除法四舍五入

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  3. 定位属性position

    定位属性position小结 1.元素为fixed(固定的),则是固定定位,即使是子元素,也不参考父元素的位置,即以浏览器作为参考定位.相当于电脑屏幕的一只蚂蚁,你无论怎么滑动屏幕,还是在原来的位置. ...

  4. Django中cookie和session使用

    cookie和session的简单使用 def cookie(request): """ 操作cookie """ resp = HttpR ...

  5. jQuery-AutoComplete自动提示简单实现

    注:本次案列实现功能为 用户注册信息,如果数据库对应表中存在部分信息,点击已有的用户的用户名,自动补全其它已有的基本信息 实现思路:通过AutoComplete提示,异步通过用户名查询全表,充当Aut ...

  6. 3、配置XShell上传文件

    1.yum   -y  install  lrzsz(安装 lrzsz) 2.rz -y(会弹出选择文件框,选择上传文件)

  7. NABCD分析---校园服务

    N(需求): 大学生活中,很多琐碎的小事浪费同学时间精力.我们的APP本着为同学服务的宗旨,解决生活中各方面的问题,同学们可以在APP上发布各种信息,例如兼职,二手买卖等等. A(做法): 用户打开A ...

  8. BDD中数据的类型及处理方法(python)

    BDD中提供了两种数据类型,table和text,以下是数据的文档介绍,最后有我的两个小例子. 1.class behave.model.Table(headings, line=None, rows ...

  9. pandas处理时间序列(3):重采样与频率转换

    五.重采样与频率转换 1. resample方法 rng = pd.date_range('1/3/2019',periods=1000,freq='D') rng 2. 降采样 (1)resampl ...

  10. Markdown学习示例

    Markdown学习示例 什么是Markdown Markdown是一种在web显示带样式风格文本的方式.你能通过它控制文本的字体样式.插入图片.插入列表等.通常,Markdown使用一些特殊的非字母 ...