Created
September 6, 2011 22:30
-
-
Save edavis10/1199189 to your computer and use it in GitHub Desktop.
Take a full page screenshot of a website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'trollop' | |
require 'vapir' | |
def filename_for_url(url) | |
url. | |
downcase. | |
gsub(/https?:\/\//,''). | |
gsub(/\//, '_'). | |
gsub(/[^0-9A-za-z.]/,'') + ".png" | |
end | |
def print_file_name(file) | |
puts file | |
end | |
opts = Trollop::options do | |
opt :url, "URL to screenshot", :default => '' | |
opt :force, "force saving", :default => false | |
end | |
Trollop::die :url, "url required" if opts[:url].nil? || opts[:url] == '' | |
file = filename_for_url(opts[:url]) | |
Trollop::die :url, "file exists, use --force to override" if (File.exists?(file) && !opts[:force]) | |
begin | |
browser = Vapir::Firefox.new | |
browser.goto opts[:url] | |
browser.screen_capture file | |
print_file_name(file) | |
ensure | |
browser.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment