在Ubuntu/debian Server 系统使用Chrome 无头浏览模式
🕧 by pyList at 2020-04-09 11:41
这里说的Ubuntu/debian Server 系统指的是无界面的服务器,一般使用 ssh 登录操作。下面介绍在服务器系统安装chrome 浏览器及使用chrome headless 模式。
安装 chrome
下载 google chrome amd64当前最新稳定版
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
可以使用 apt install
安装
apt install ./google-chrome-stable_current_amd64.deb
这种安装方法会安装一些依赖库,并且会添加更新源,可以屏蔽它。
$ cat /etc/apt/sources.list.d/google-chrome.list
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
# deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
把文件 /etc/apt/sources.list.d/google-chrome.list
最后一行注释掉。
也可以使用 dpkg
安装,这种安装方法会忽略掉一些依赖,但我在使用中也没有出现问题。
apt-get install libxss1 libappindicator1 libindicator7
apt-get install curl
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome*.deb
apt-get install -f
成功安装后看chrome信息,我是用上面第一种方式安装。
$ apt info google-chrome-stable
Package: google-chrome-stable
Version: 80.0.3987.149-1
Status: install ok installed
Priority: optional
Section: web
Maintainer: Chrome Linux Team <chromium-dev@chromium.org>
Installed-Size: 224 MB
Provides: www-browser
Pre-Depends: dpkg (>= 1.14.0)
Depends: ca-certificates, fonts-liberation, libappindicator3-1, libasound2 (>= 1.0.16), libatk-bridge2.0-0 (>= 2.5.3), libatk1.0-0 (>= 2.2.0), libatspi2.0-0 (>= 2.9.90), libc6 (>= 2.16), libcairo2 (>= 1.6.0), libcups2 (>= 1.4.0), libdbus-1-3 (>= 1.5.12), libexpat1 (>= 2.0.1), libgcc1 (>= 1:3.0), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.39.4), libgtk-3-0 (>= 3.9.10), libnspr4 (>= 2:4.9-2~), libnss3 (>= 2:3.22), libpango-1.0-0 (>= 1.14.0), libpangocairo-1.0-0 (>= 1.14.0), libx11-6 (>= 2:1.4.99.1), libx11-xcb1, libxcb1 (>= 1.6), libxcomposite1 (>= 1:0.3-1), libxcursor1 (>> 1.1.2), libxdamage1 (>= 1:1.1), libxext6, libxfixes3 (>= 1:5.0), libxi6 (>= 2:1.2.99.4), libxrandr2 (>= 2:1.2.99.3), libxrender1, libxss1, libxtst6, wget, xdg-utils (>= 1.0.2)
Recommends: libu2f-udev
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: The web browser from Google
Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.
用命令行测试
$ google-chrome --headless --disable-gpu --no-sandbox --remote-debugging-port=9222 https://chromium.org
DevTools listening on ws://127.0.0.1:9222/devtools/browser/7ad1e1f8-52f4-4a85-b616-a9bbd62daccd
必须加 --headless --disable-gpu --no-sandbox
这三个运行选项才能启动。
安装 chromedriver
我这里使用官方的驱动,
官方下载地址 https://sites.google.com/a/chromium.org/chromedriver/downloads 18
选择上面安装的Chrome 版本,选择对应的系统,如 chromedriver_linux64.zip
$ wget https://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_linux64.zip
$ unzip chromedriver_linux64.zip
$ cp chromedriver /usr/bin/
$ chromedriver -h
Usage: chromedriver [OPTIONS]
Options
--port=PORT port to listen on
--adb-port=PORT adb server port
--log-path=FILE write server log to file instead of stderr, increases log level to INFO
--log-level=LEVEL set log level: ALL, DEBUG, INFO, WARNING, SEVERE, OFF
--verbose log verbosely (equivalent to --log-level=ALL)
--silent log nothing (equivalent to --log-level=OFF)
--append-log append log file instead of rewriting
--replayable (experimental) log verbosely and don't truncate long strings so that the log can be replayed.
--version print the version number and exit
--url-base base URL path prefix for commands, e.g. wd/url
--readable-timestamp add readable timestamps to log
--disable-dev-shm-usage do not use /dev/shm (add this switch if seeing errors related to shared memory)
安装操作库
python 可以用 selenium
$ pip install selenium
golang 推荐用 tebeka/selenium
https://github.com/tebeka/selenium
如果用 python 驱动最低内存是256MB,否则 chrome 容易崩溃,推荐512MB以上。
用go 会省点内存和cpu,最低内存是256MB。
其它安装
下面是个人需要,做一下记录。
go 环境安装
https://golang.google.cn/dl/ 1
$ wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.14.1.linux-amd64.tar.gz
$ vi /etc/profile
export PATH=$PATH:/usr/local/go/bin
$ source /etc/profile
$ go -h
当go 库调用cgo 时,需要安装编译依赖
apt install build-essential
源码编译安装 OpenCC
git clone https://github.com/BYVoid/OpenCC.git
apt-get install cmake
apt-get install doxygen
cd OpenCC
make
make install
本文网址: https://pylist.com/t/1586403682 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
发表第一条评论!
相关推荐
小工具
标签
cpu
debian
ubuntu
查看
温度
gnu
linux
安装
系统启动
usb
mac
固件
openwrt
编译
跨域
server
tornado
websocket
问题
python
老旧
服务器
笔记本
改造
记录
golang
正则
字符串
切割
硬件加速
ubnt
er
路由
变砖
arris
ac1750
sbr
bbr
开启
访问速度
vps
加速
google
身份验证
authenticator
迁移
手机
静音
风扇
主机
之坑
files
open
服务
最新版
wndr4300
升级
默认值
struct
设置
html
中文
实体
转换
api
搜索引擎
网址
提交
自动
虚拟机
virtualbox
很慢
网络
解决
自动更新
microsoft
关闭
app
store
登录
未知
低功耗
web
爬虫
组装
微信
尝鲜
视频
体验
chrome
浏览
webdriver
微博
selenium
宅家
坑记
屏幕
动手
nginx
quic
抢先
useragent
蜘蛛
真假
识别
最近发表
- Mac 关闭 Microsoft 自动更新
- Mac 登录 App Store 出现“发生了未知错误”的解决方法
- 老笔记本改造为无风扇静音主机方案
- 自己组装21瓦低功耗家庭爬虫、文件、web服务器
- 微信视频号尝鲜体验
- Ubuntu/Debian 查看CPU温度的方法
- 在Ubuntu/debian Server 系统使用Chrome 无头浏览模式
- 换手机后 Google 身份验证器 Google Authenticator 数据迁移的简单方法
- 使用Golang selenium WebDriver 自动登录微博
- 在 Ubuntu 或其它 GNU/Linux 系统下安装 Debian
- Mac 下制作 USB ubuntu/debian 系统启动、安装盘的几种方法
- ubuntu/debian 下自行编译 OpenWRT 固件
- 宅家自己动手换手机屏幕掉坑记
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- 在 Nginx 和 Golang web 上抢先体验 QUIC
- 从UserAgent识别搜索引擎并判断真假蜘蛛
最近浏览
- 把老旧笔记本改造为家庭服务器过程记录
- Mac 下制作 USB ubuntu/debian 系统启动、安装盘的几种方法
- Ubuntu/Debian 查看CPU温度的方法
- Golang 正则切割字符串
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- ARRIS SBR-AC1750 路由变砖拆解折腾
- Openwrt 路由上开启BBR
- 开启BBR 加速小VPS访问速度
- 换手机后 Google 身份验证器 Google Authenticator 数据迁移的简单方法
- 老笔记本改造为无风扇静音主机方案
- Golang 服务之坑:too many open files
- WNDR4300 固件升级到 OpenWrt 最新版
- go struct 设置默认值
- 用python 实现中文与html实体相互转换
- 利用 API 自动向搜索引擎提交网址
- VirtualBox 虚拟机里网络很慢的解决方法