Skip to content

Instantly share code, notes, and snippets.

@soh335
Created September 17, 2010 01:17
Show Gist options
  • Save soh335/583491 to your computer and use it in GitHub Desktop.
Save soh335/583491 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
require 'open-uri'
username = ''
password = ''
#Mechanizeの設定
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
#ログイン処理
page = agent.get('http://mixi.jp/')
form = page.forms[0]
form.fields.find {|f| f.name == 'email'}.value = username
form.fields.find {|f| f.name == 'password'}.value = password
form.fields.find {|f| f.name == 'next_url'}.value = '/home.pl'
results = agent.submit(form)
#対象コミュニティページのURL
url = ["http://mixi.jp/view_community.pl?id=1390708",
"http://mixi.jp/view_community.pl?id=657724",
"http://mixi.jp/view_community.pl?id=629852"
]
get_category = []
url.each do |a|
agent.get(a).search('//dl[contains(concat(" ",@class," "), " categoryName ")]/dd').each do |b|
p b.text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment