Last active
August 29, 2015 13:56
-
-
Save workmad3/8974238 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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() | |
) |
This file contains hidden or 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
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