mixiのコミュニティ最新書き込みのタイトル一覧を取得するため、Mixiの自分の日記を取得するに下記のクラスとMixiクラスにメソッドを追加した。
class TopicTitle attr_reader :title attr_reader :community def initialize(title, community) @title = title @community = community end end
def getNewTopicTitles() http = Net::HTTP.start('mixi.jp') response = http.get('/new_bbs.pl', 'Cookie' => @cookie) body = response.body.toutf8 titles = Array.new body.scan(/<a href="view_bbs.pl\?id=\d+&comment_count=\d+&comm_id=\d+">([^<]+)<\/a> \((.+?)\)<\/dd>/){|title, community| titles << TopicTitle.new(title, community) } return titles end
使い方は
mixi = Mixi.new mixi.login(email, password) mixi.getNewTopicTitles().each{|title| puts "#{title.title} (#{title.community})" }