Skip to content

Instantly share code, notes, and snippets.

@edavis10
Created September 6, 2011 22:30
Show Gist options
  • Save edavis10/1199189 to your computer and use it in GitHub Desktop.
Save edavis10/1199189 to your computer and use it in GitHub Desktop.
Take a full page screenshot of a website.
#!/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
@edavis10
Copy link
Author

edavis10 commented Sep 6, 2011

Why? Because I'm on Linux and because I can.

@ixti
Copy link

ixti commented Sep 6, 2011

"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)

@mgrachev
Copy link

mgrachev commented Jan 8, 2016

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