Skip to content

Instantly share code, notes, and snippets.

@m040601
Forked from shokai/hatena-land-post.rb
Created October 14, 2010 10:13
Show Gist options
  • Save m040601/625978 to your computer and use it in GitHub Desktop.
Save m040601/625978 to your computer and use it in GitHub Desktop.
hatena posts - noko/mech/openuri
#!/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