Skip to content

Instantly share code, notes, and snippets.

@workmad3
Last active August 29, 2015 13:56
Show Gist options
  • Save workmad3/8974238 to your computer and use it in GitHub Desktop.
Save workmad3/8974238 to your computer and use it in GitHub Desktop.
page = require('webpage').create()
url = phantom.args[1]
output = phantom.args[2]
page.open(url, (status)->
console.log "Status: #{status}"
page.render "#{output}.png"
console.log "Took screenshot #{output}.png"
console.log 'Exiting...'
phantom.exit()
)
namespace :scrape do
desc "Take a screenshot of a url using Phantomjs"
task :screenshots => :environment do
f = File.join(Rails.root, 'app', 'assets', 'javascripts', 'screenshot.js.coffee').gsub(/ /, '\ ')
articles = Article.order('zscore DESC').limit(3)
articles.each_with_index do |article, i|
`phantomjs #{f} #{article.url} screenshot-#{i}`
sleep 4
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment