User Tools

Site Tools


automate_taking_screenshots_of_webpages

Automate_taking_screenshots_of_webpages

Intro

I wanted to setup cron to take screenshots of various websites on a daily basis. There are different approaches available. One is using wkhtmltopdf (still requires additional packages), another is using http://browsershots.org/documentation#RequirementsForFactories (requires vncserver). The approach I chose was to manually setup VNCserver and firefox (iceweasel) and script it myself.

Main Script

The following script starts a VNC session, starts firefox (iceweasel on debian) with a url and takes a screenshot, saving the image with the filename: 01-06-2011_22:13_www.domain.com.jpg #!/bin/sh

# start a server with a specific DISPLAY vncserver :11 -geometry 1024×768

# read URLs from a data file in a loop for url in `cat list.txt` do

      firefox --display=:11 $url &
      sleep 5
      eval "import -display :11 -window root" `date +"%d-%m-%Y_%k:%M"`"_"`echo|awk '{print substr(v1,8)}' v1=$url`".jpg"

done # clean up when done vncserver -kill :11

list.txt contains a list of URLs in the format: http://www.domain.com http://www.google.com http://slashdot.org #awk is then used to remove the http: and use the url as part of the filename ====== Pre-Requesites ====== The above was done on debian squeeze. apt-get install imagemagick #This package provides the import command. Xfce-vncserver #The above page describes installing an Xserver and firefox/iceweasel ====== References ====== Main Reference: http://stackoverflow.com/questions/125951/command-line-program-to-create-website-screenshots-on-linux <br> http://tips.webdesign10.com/how-to-take-a-screenshot-with-ubuntu-linux

automate_taking_screenshots_of_webpages.txt · Last modified: 2022/07/19 21:13 by 127.0.0.1