Skip to content

Instantly share code, notes, and snippets.

@gamafranco

gamafranco/screenshot.rb

Forked from asbubam/screenshot.rb
Last active Oct 17, 2018
Embed
What would you like to do?
webkit screen capture using by capybara-webkit gem
#!/usr/bin/env ruby
require 'capybara-webkit'
require 'headless'
urls = [
'https://www.linkedin.com/feed/update/urn:li:activity:6445944267885154304/',
'https://www.bbc.com/news/technology-45546275',
'https://twitter.com/theipaper/status/1046784302006976512',
'https://twitter.com/DailyMailUK/status/1047014074561847296',
'https://www.dailymail.co.uk/news/article-6229029/Now-sale-UK-high-protein-meal-glass-health-drink.html',
'https://uk.finance.yahoo.com/news/soylent-apos-meal-replacement-drinks-103000758.html?guccounter=1',
'https://www.engadget.com/2018/09/18/soylent-meal-replacement-drinks-uk/',
'https://www.engadget.com/2018/09/18/soylent-meal-replacement-drinks-uk/#%22%20style=%22visibility:hidden%22/%3E%3Cspan%20id=%22te-clearads-js-efrontier01cont1%22%3E%3Cscript%20type=%22text/javascript%22%20src=%22https://choices.truste.com/ca?pid=efrontier01&aid=efrontier01&cid=0911ef120x240&c=efrontier01cont1&w=307&h=173&plc=tr&js=10%22%3E%3C/script%3E%3C/span%3E&tm_asset_id=built-inBtIcon_647785725424&tm_origin=https://www.engadget.com/2018/09/18/soylent-meal-replacement-drinks-uk/',
'https://www.bbc.co.uk/news/technology-45546275',
'https://www.beveragedaily.com/Article/2018/09/17/Soylent-cult-following-in-the-US-leads-to-UK-launch'
]
mentions = [
[10990, "https://twitter.com/Telegraph/status/1028397275997986816"],
[10873, "https://www.instagram.com/p/Bmf0TEKALPl/?hl=en&taken-by=thegrocerofficial"],
[11017, "https://discordapp.com/channels/285893756849225728/306139452798140417"],
[11133, "https://twitter.com/guardian/status/1039544033943674887"],
[11136, "https://www.facebook.com/theguardian/?hc_ref=ARQigRR4x-g6Cl3F5AluWmW6A1UiW8uyHMg0F0a6WmtmifoLgHq0MgykiLX5q-bFLOs&fref=nf&__xts__[0]=68.ARDH4JrOajL8dQfVv0sqavu_-ntmsQBEOOZQ9sMtgL7VR9x8Ch5TwO9-lxB98uXFzP1bAHDLdcAAXlQozRhKSEWQWaInMJ6fAv2pm5laLKLAMZzmfPFzLBQW-LGjMPaebzjle2Dr60EBl7jJBTp1uWaT_oFZGUBZiGz_d1fqRNzzjg3vl2GJ7FI&__tn__=kC-R"],
[11137, "https://www.facebook.com/TeamEndpoint/"],
[11163, "https://twitter.com/vicearoni"],
[11164, "https://www.linkedin.com/feed/update/urn:li:activity:6445944267885154304/"],
[11178, "https://twitter.com/plantbasednews/status/1040631085326118912"],
[11184, "https://twitter.com/tomough/status/1040560610667384833"]
]
Capybara::Webkit.configure do |config|
# Enable debug mode. Prints a log of everything the driver is doing.
# config.debug = true
# By default, requests to outside domains (anything besides localhost) will
# result in a warning. Several methods allow you to change this behavior.
# Silently return an empty 200 response for any requests to unknown URLs.
# config.block_unknown_urls
# Allow pages to make requests to any URL without issuing a warning.
config.allow_unknown_urls
# Allow a specific domain without issuing a warning.
# config.allow_url("example.com")
# Allow a specific URL and path without issuing a warning.
# config.allow_url("example.com/some/path")
# Wildcards are allowed in URL expressions.
# config.allow_url("*.example.com")
# Silently return an empty 200 response for any requests to the given URL.
# config.block_url("example.com")
# Timeout if requests take longer than 5 seconds
# config.timeout = 5
# Don't raise errors when SSL certificates can't be validated
# config.ignore_ssl_errors
# Don't load images
# config.skip_image_loading
# Use a proxy
# config.use_proxy(
# host: "example.com",
# port: 1234,
# user: "proxy",
# pass: "secret"
# )
# Raise JavaScript errors as exceptions
# config.raise_javascript_errors = true
end
# urls.each_with_index do |url, index|
# Headless.ly do
# driver = Capybara::Webkit::Driver.new 'url', :cookies => true
# driver.visit url
# driver.save_screenshot "out#{index}.png"
# end
mentions.each do |mention|
mention_id = mention[0]
url = mention[1]
driver = Capybara::Webkit::Driver.new url, :cookies => true
driver.visit url
driver.save_screenshot "#{mention_id}.png"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment