Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@edavis10 edavis10 commented Sep 6, 2011

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

@ixti

This comment has been minimized.

Copy link

@ixti 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

This comment has been minimized.

Copy link

@mgrachev 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