主要原理是利用xvfb提供的显卡帧缓冲区,让浏览器以为有桌面@H_301_1@
Install xvfb in ubuntu:@H_301_1@
sudo apt install xvfb@H_301_1@
cat > /etc/init.d/xvfb <<"EOF"@H_301_1@
XVFB=/usr/bin/Xvfb@H_301_1@
XVFBARGS=":99 -screen 0 1024x768x24 -fbdir /var/run -ac"@H_301_1@
PIDFILE=/var/run/xvfb.pid@H_301_1@
case "$1" in@H_301_1@
start)@H_301_1@
echo -n "Starting virtual X frame buffer: Xvfb"@H_301_1@
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS@H_301_1@
echo "."@H_301_1@
;;@H_301_1@
stop)@H_301_1@
echo -n "Stopping virtual X frame buffer: Xvfb"@H_301_1@
start-stop-daemon --stop --quiet --pidfile $PIDFILE@H_301_1@
echo "."@H_301_1@
;;@H_301_1@
restart)@H_301_1@
$0 stop@H_301_1@
$0 start@H_301_1@
;;@H_301_1@
*)@H_301_1@
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"@H_301_1@
exit 1@H_301_1@
esac@H_301_1@
exit 0@H_301_1@
EOF@H_301_1@
chmod +x /etc/init.d/xvfb@H_301_1@
export DISPLAY=:99.0@H_301_1@
/etc/init.d/xvfb start@H_301_1@
1.2. Install chrome in ubuntu:@H_301_1@
sudo apt-get install libxss1 libappindicator1 libindicator7@H_301_1@
sudo apt-get install -f@H_301_1@
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb@H_301_1@
sudo dpkg -i google-chrome*.deb@H_301_1@
sudo ln -s /usr/bin/google-chrome /usr/bin/chrome@H_301_1@
1.3. Install chromedriver in ubuntu:@H_301_1@
wget http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip@H_301_1@
unzip chromedriver_linux64.zip@H_301_1@
sudo mv chromedriver /usr/bin/@H_301_1@
1.4. Install firefox in ubuntu:@H_301_1@
sudo apt install firefox@H_301_1@
1.5. Install geckodriver for firefox in ubuntu:@H_301_1@
wget https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz@H_301_1@
tar zxf geckodriver-v0.11.1-linux64.tar.gz@H_301_1@
sudo mv geckodriver /usr/bin/@H_301_1@