#!/usr/local/bin/ruby #hatena_counter.rb require 'open-uri' require "pp" require 'uri' text = <<"EOS" 2006年09月の人気記事 - はてな匿名ダイアリー

2006年09月の人気記事

2017010203040506070809
2016010203040506070809101112
2015010203040506070809101112
2014010203040506070809101112
2013010203040506070809101112
2012010203040506070809101112
2011010203040506070809101112
2010010203040506070809101112
2009010203040506070809101112
2008010203040506070809101112
2007010203040506070809101112
200609101112
アーカイブ ヘルプ
ログイン ユーザー登録
ようこそ ゲスト さん
EOS =begin target_date = [] urls = ["https://anond.hatelabo.jp/archive/200609"] urls.each do |url| OpenURI.open_uri(url).each_line do |html| new_line_has_been_html = html.gsub(/
  • /, "\n
  • ") new_line_has_been_html.each_line do |line| if line =~ %r|
  • .+| target_date << line.slice(%r|
  • .+|, 1) end end end end =end #url = 'http://mukar.com/test.cgi?cont=日本語テスト ホゲホゲ' #url_escape = URI.escape(url) #puts url_escape #=> http://mukar.com/test.cgi?cont=%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%83%86%E3%82%B9%E3%83%88%20%E3%83%9B%E3%82%B2%E3%83%9B%E3%82%B2 #puts URI.unescape(url_escape) #=>http://mukar.com/test.cgi?cont=日本語テスト ホゲホゲ # # ↑こいつ最高にアホ! はわわわ アイコンをアバターとしたチャット。ともだちられシステムは.. target_pairs = [] target_date = [] target_title = [] =begin #エントリーの日付を取得 text.each_line do |html| html.gsub(/
  • /, "\n
  • ").each_line do |line| target_date << line.slice(%r|href="(/2\d+)">(.+).+/, "\n
  • ").each_line do |line| target_title << line.slice(%r|href="(/2\d+)">(.+) .+ (.+) |, 2) if line =~ %r|href="/2\d+">.+ | #エントリーが2種類に別れる。仕様の詳細は不明 end end =end target_date_and_title = [] #エントリーの日付とタイトルを取得 text.each_line do |html| html.gsub(/
  • /, "\n
  • ").each_line do |line| date = line.slice(%r|href="(/2\d+)">(.+).+(.+) .+ (.+) |, 2) if line =~ %r|href="/2\d+">.+ | #エントリーが2種類に別れる。仕様の詳細は不明 target_date_and_title << [date, title] end end #target_pairs.each do |d| # puts URI.unescape(d) #end #エントリーの日付とタイトルを合成 #target_date_and_title = [target_date, target_title].transpose target_date_and_title.each do |d| puts d if d == nil end pp target_date_and_title