yum -y install redhat-lsb
(base) [root@nlu-ca-1 firefox]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
yum install firefox -y
#可能不是最新版本
wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/91.0b7/linux-x86_64/zh-CN/firefox-91.0b7.tar.bz2
#解压到/usr/local/firefox
#将/usr/local/firefox添加到环境变量PATH中
vim /etc/profile
export PATH=$PATH:/usr/local/firefox
source /etc/profile
yum install system-config-language wqy-unibit-fonts cjkuni-ukai-fonts lrzsz -y
这一步很重要,不然打开的中文网站,中文部分都是乱码哦
system-config-language --text #设置简体中文显示
source /etc/locale.conf
echo $LANG # 显示zh_CN.UTF-8即可
(base) [root@nlu-ca-1 tmp]# firefox --headless --no-remote --new-instance -screenshot baidu.png https://www.baidu.com
*** You are running in headless mode.
[GFX1-]: glxtest: Unable to open a connection to the X server
[GFX1-]: glxtest: libEGL initialize failed
###!!! [Parent][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
会报些错误,不知道为什么
低版本的试了下,不报错,可以用
yum -y install firefox #也可以通过上面的url方式下载
firefox -version
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
Mozilla Firefox 78.12.0esr
截图:
firefox --headless -screenshot baidu.png https://www.baidu.com
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
*** You are running in headless mode.
这个错误【Failed to open connection to “session” message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11】
解决方式是:
yum install dbus-x11 dbus -y
在每次截图前执行
eval `dbus-launch --sh-syntax`
(base) [root@nlu-ca-2 ~]# firefox --headless -screenshot baidu.png https://www.baidu.com
Running without a11y support!
*** You are running in headless mode.
WebVector is an HTML to SVG or PNG convertor. It converts a HTML document into a vector image in SVG format or a bitmap image in PNG format. The Standard Vector Graphics (SVG) files can be further edited by a variety of vector graphics editors such as Inkscape.
http://cssbox.sourceforge.net/webvector/
CutyCapt is a small cross-platform command-line utility to capture WebKit’s rendering of a web page into a variety of vector and bitmap formats, including SVG, PDF, PS, PNG, JPEG, TIFF, GIF, and BMP. See IECapt for a similar tool based on Internet Explorer.
wkhtmltopdf and wkhtmltoimage are open source (LGPL) command line tools to render HTML into PDF and various image formats using the QT Webkit rendering engine. These run entirely “headless” and do not require a display or display service. There is also a C library, if you’re into that kind of thing.
另外,使用chrome也可以达到相同的目的
参考:https://www.cnblogs.com/imyalost/p/9079076.html
备注:该方法也要保证操作系统的LANG为中文
yum -y install xorg-x11-server-Xvfb-1.20.1-3.el7.x86_64.rpm
yum -y install google-chrome-stable_current_x86_64.rpm
yum install -y epel-release
yum install -y chromium
yum -y install python-qt4 libqt4-webkit python-pip
Another easy way is using (phantomjs)[https://phantomjs.org/]
phantomjs:
$ phantom rasterize.js https://www.baidu.com baidu.png
Download and unzip the binary archive. rasterize.js is in the example directory.