Centos(linux)下cutycapt安裝使用教程

來源:互聯網
上載者:User

在Centos(linux)安裝cutycapt

Install CutyCapt on Centos

開啟 EPEL repository

CentOS 7

yum install epel-release

CentOS 6 or Earlier

rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

CentOS/RHEL 5.*

rpm -Uvh http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm


安裝cutycapt


運行cutycapt報錯

cutycapt: cannot connect to X server :0
還需要安裝Xvfb

yum install Xvfb

安裝完Xvfb以後 ,cutycapt運行一下命令列

xvfb-run –server-args=”-screen 0, 1280×1200x24″ cutycapt –url=http://www.cnn.com –out=cnn.png

同時產生多張圖片的話,把Xvfb服務後端運行

touch /etc/init.d/xvfb with content: 

#!/bin/bash
#
# /etc/rc.d/init.d/xvfbd
#
# chkconfig: 345 95 28
# description: Starts/Stops X Virtual Framebuffer server
# processname: Xvfb

. /etc/init.d/functions 

[ "${NETWORKING}" = "no" ] && exit 0 

PROG="Xvfb"
PROG_OPTIONS=":7 -ac -screen 0 1024x768x24"
PROG_OUTPUT="/tmp/Xvfb.out" 

case "$1" in
    start)
        echo -n "Starting : X Virtual Frame Buffer "
        $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
        disown -ar
        /bin/usleep 500000
        status Xvfb & >/dev/null && echo_success || echo_failure
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            /bin/touch /var/lock/subsys/Xvfb
            /sbin/pidof -o  %PPID -x Xvfb > /var/run/Xvfb.pid
        fi
        echo
        ;;
    stop)
        echo -n "Shutting down : X Virtual Frame Buffer"
        killproc $PROG
        RETVAL=$?
        [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb /var/run/Xvfb.pid
        echo
        ;;
    restart|reload)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
    status)
        status Xvfb
        RETVAL=$?
        ;;
    *)
     echo $"Usage: $0 (start|stop|restart|reload|status)"
     exit 1
esac 

exit $RETVAL 

Registering in system and start:
chmod +x /etc/init.d/xvfb
chkconfig xvfb on
service xvfb start 

now 

export DISPLAY=:7 (actually you should add this to your etc/bashrc)

例子,在一台不含X的伺服器上使用CutyCapt將HTML轉換成PNG

雖然CutyCapt是一個命令列工具,但是它需要X服務運行。如果你嘗試在不含X服務的機器上運行,你會得到下面這個錯誤:

cutycapt: cannot connect to X server :0

如果你要不含X的伺服器上運行CutyCapt,你可以在伺服器上安裝Xvfb(輕量級“假的”X11 服務)。這樣CutyCapt就不會報錯了。

要在Debian, Ubuntu 或者 Linux Mint 上安裝Xvfb:

$ sudo apt-get install xvfb

要在Fedora, CentOS 或者 RHEL 上安裝Xvfb:

$ sudo yum install xvfb

在安裝Xvfb之後,接下來像這樣運行CutyCapt。

$ xvfb-run --server-args="-screen 0, 1280x1200x24" cutycapt --url=http://www.cnn.com --out=cnn.png

它首先會運行Xbfb服務,接著使用CutyCapt來抓取網頁。因此它可能會花費更長的時間。如果你想要截圖多張截圖,你可能事先需要將Xvfb作為後台守護進程啟動。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.