Skip to content

Instantly share code, notes, and snippets.

@yosmoc
Created July 24, 2008 14:11
Show Gist options
  • Save yosmoc/2155 to your computer and use it in GitHub Desktop.
Save yosmoc/2155 to your computer and use it in GitHub Desktop.
rm_hatenagraph.rb
# -*- coding: utf-8 -*-
require 'mechanize'
require 'pit'
require 'uri'
pit = Pit.get('hatena', :require => {
'username' => 'username',
'password' => 'password'})
BASE = URI("http://graph.hatena.ne.jp/#{pit['username']}/")
@agent = WWW::Mechanize.new
graph_page = @agent.get(BASE)
login_link = graph_page.links.text('ログイン')
login_page = @agent.get(login_link.href)
login_form = login_page.forms.first
login_form['name'] = pit['username']
login_form['password'] = pit['password']
@agent.submit(login_form)
graph_page = @agent.get(BASE)
graph_page.links.each do |link|
if link.text =~ // # ここに削除したいグラフ名にマッチした正規表現を入れる
graph = @agent.get(link.href)
p "#{link.text}を削除します"
# @agent.submit(graph.forms[2]) # コメントアウト外すと実行。
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment