Skip to content

Instantly share code, notes, and snippets.

@taaaaho
Created October 25, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taaaaho/02773c6fb44132b3a980faa263af8d50 to your computer and use it in GitHub Desktop.
Save taaaaho/02773c6fb44132b3a980faa263af8d50 to your computer and use it in GitHub Desktop.
はてなブログの記事一覧を取得する
require 'nokogiri'
require 'open-uri'
url = '[ここにはてなブログのURLを指定]'
charset = nil
continue = true;
while continue do
continue = false;
html = open(url) do |f|
charset = f.charset
f.read
end
doc = Nokogiri::HTML.parse(html, nil, charset)
doc.xpath('//a[@class="entry-title-link"]').each do | node |
p node.get_attribute(:href)
p node.inner_text
# p node.inner_text + "," + node.get_attribute(:href)
end
doc.xpath('//span[@class="pager-next"]/a').each do | node |
url = node.get_attribute(:href)
continue = true;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment