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 |
"Because I'm on Linux and because I can."
ROFL! :)) Absolutely agree! It's better to keep focus on making things awesome, then on making them compatible with system (every new version of which is almost 90% not-compatible with previous one)
For this you can use the gem gastly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why? Because I'm on Linux and because I can.