Skip to content

Instantly share code, notes, and snippets.

@workmad3
Last active August 29, 2015 13:56

Revisions

  1. workmad3 revised this gist Feb 13, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions screenshots.rake
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    namespace :scrape do
    desc "Take a screenshot of a url using Phantomjs"
    task :screenshots => :environment do
    require 'capybara'
    require 'poltergeist/capybara'
    include Capybara::DSL
    Capybara.default_driver = :poltergeist

    articles = Article.order('zscore DESC').limit(3)
    articles.each_with_index do |article, i|
  2. workmad3 revised this gist Feb 13, 2014. 2 changed files with 3 additions and 14 deletions.
    12 changes: 0 additions & 12 deletions screenshots.js.coffee
    Original file line number Diff line number Diff line change
    @@ -1,12 +0,0 @@
    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()
    )
    5 changes: 3 additions & 2 deletions screenshots.rake
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    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(/ /, '\ ')
    include Capybara::DSL

    articles = Article.order('zscore DESC').limit(3)
    articles.each_with_index do |article, i|
    `phantomjs #{f} #{article.url} screenshot-#{i}`
    visit article.url
    screenshot_and_save_page
    sleep 4
    end
    end
  3. @DaniG2k DaniG2k revised this gist Feb 13, 2014. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions screenshots.js.coffee
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    page = require('webpage').create()

    url = phantom.args[0]
    output = phantom.args[1]
    url = phantom.args[1]
    output = phantom.args[2]

    page.open(url, (status)->
    console.log "Status: #{status}"
    4 changes: 2 additions & 2 deletions screenshots.rake
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    namespace :scrape do
    desc "Take a screenshot of a url using Phantomjs"
    task :screenshots => :environment do
    asset = ActionController::Base.helpers.asset_path('screenshot.js.coffee')
    f = File.join(Rails.root, 'app', asset).gsub(/ /, '\ ')
    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
  4. @DaniG2k DaniG2k revised this gist Feb 13, 2014. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions screenshots.js.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    page = require('webpage').create()

    url = phantom.args[0]
    output = phantom.args[1]

    page.open(url, (status)->
    console.log "Status: #{status}"
    page.render "#{output}.png"
    console.log "Took screenshot #{output}.png"
    console.log 'Exiting...'
    phantom.exit()
    )
  5. @DaniG2k DaniG2k created this gist Feb 13, 2014.
    12 changes: 12 additions & 0 deletions screenshots.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    namespace :scrape do
    desc "Take a screenshot of a url using Phantomjs"
    task :screenshots => :environment do
    asset = ActionController::Base.helpers.asset_path('screenshot.js.coffee')
    f = File.join(Rails.root, 'app', asset).gsub(/ /, '\ ')

    articles = Article.order('zscore DESC').limit(3)
    articles.each_with_index do |article, i|
    `phantomjs #{f} #{article.url} screenshot-#{i}`
    end
    end
    end