Skip to content

Instantly share code, notes, and snippets.

@shokai
Created October 5, 2010 14:55
Show Gist options
  • Save shokai/611679 to your computer and use it in GitHub Desktop.
Save shokai/611679 to your computer and use it in GitHub Desktop.
hatena land
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
require 'nokogiri'
require 'kconv'
require 'open-uri'
USER = 'username'
PASS = 'passpass'
@agent = Mechanize.new
@agent.user_agent_alias = 'Windows IE 7'
page = @agent.get('https://www.hatena.ne.jp/login?auto=0&backurl=http%3A%2F%2Fl.hatena.ne.jp%2F')
login_form = page.forms.first
login_form.fields_with(:name => 'name').first.value = USER
login_form.fields_with(:name => 'password').first.value = PASS
login_form.click_button
page = @agent.get('http://l.hatena.ne.jp/')
post_form = page.forms.first
post_form.fields_with(:name => 'body_text').first.value = 'test'
post_form.click_button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment