Skip to content

Instantly share code, notes, and snippets.

@gn-spawn
Created September 30, 2015 05:27
Show Gist options
  • Save gn-spawn/9bb3604e606dab57f8a8 to your computer and use it in GitHub Desktop.
Save gn-spawn/9bb3604e606dab57f8a8 to your computer and use it in GitHub Desktop.
sample
require 'open-uri'
require 'nokogiri'
URL = 'http://heavens-fox.blog.jp/'
html = open(URL) { |f| f.read }
doc = Nokogiri::HTML.parse(html, nil)
class BabymetalArticle
def initialize(article)
@title = article.css("h1.article-title > a").text
@summary = article.css("div.article-body-inner").text
@comments = article.css("li.article-comment-count > dl > dd >a").text.to_i
end
def put_console
puts @title
puts @summary
puts @comments
end
end
articles = doc.css("div.article-inner").map do |article|
BabymetalArticle.new article
end
articles.each {|article| article.put_console}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment