Skip to content

Instantly share code, notes, and snippets.

@denysonique
Last active December 20, 2015 08:59
Show Gist options
  • Save denysonique/6104206 to your computer and use it in GitHub Desktop.
Save denysonique/6104206 to your computer and use it in GitHub Desktop.
require 'scrapify'
require 'models'
module HN
class Scraper < Scrapify::Page
encoding 'utf-8'
fields = {
comment: 'comment.div',
title: 'title',
}
#fields do |f|
#
# f 'comment', 'comment.div'
# f 'title' , 'title'
#end
item_class ArticlePreview
item_preview_class ArticlePreview
end
class ArticilePreview < Scrapify::ItemPreview
end
class Article < Scrapify::Item
selector '.article'
fields do |f|
f 'title', '.title'
f 'url', '.link a'
f 'upvotes', '.vote.count'
end
end
end
HN::Scraper.each_article do |article|
a = DM::Article
a.title = article[:title]
a.upvotes = article[:upvotes]
a.url = article[:url]
a.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment