Last active
December 20, 2015 08:59
-
-
Save denysonique/6104206 to your computer and use it in GitHub Desktop.
This file contains 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
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