Skip to content

Instantly share code, notes, and snippets.

@ZucchiniZe
Created January 23, 2015 02:10
Show Gist options
  • Select an option

  • Save ZucchiniZe/e6dd3ff4d137252131de to your computer and use it in GitHub Desktop.

Select an option

Save ZucchiniZe/e6dd3ff4d137252131de to your computer and use it in GitHub Desktop.
require 'capybara'
require 'capybara/poltergeist'
require 'awesome_print'
Capybara.app_host = 'http://alexb.ninja/blog'
Capybara.current_driver = :poltergeist
Capybara.run_server = false
module API
class << self
include Capybara::DSL
def posts
visit '/'
posts = []
all('.posts li').each_with_index do |post,i|
posts[i] = {
:title => post.find('p[itemprop]').text,
:url => post.find('a')['href'],
:time => post.find('time').text,
:datetime => post.find('time')['datetime']
}
end
posts.each do |post|
visit post[:url][5..post[:url].length]
post[:body] = find('div[itemprop=articleBody]').text
post[:wordcount] = post[:body].split.size
post[:readingtime] = (post[:wordcount] / 180).ceil
end
end
end
end
ap API::posts, options = {:indent => 2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment