Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created January 16, 2010 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/278835 to your computer and use it in GitHub Desktop.
Save mizchi/278835 to your computer and use it in GitHub Desktop.
#/usr/bin/python
# -*- encoding:utf8 -*-
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
url='http://mixi.jp'
username="<your email>"
password="<your password>"
mixi_id=<your id-number>
def login():
try:
br.open(url)
br.select_form(name="login_form")
br["email"] = username
br["password"] = password
br.submit()
return True
except:
return False
def write(title,body):
br.open('http://mixi.jp/add_diary.pl?id=%u&send_from=home' % mixi_id)
br.select_form(name="diary")
br["diary_title"] = title.encode(br.encoding())
br["diary_body"] = body.encode(br.encoding())
res=br.submit()
print res.geturl()
br.submit()
if login() : print "Login OK"
elif print "Login Failure"
write("test","hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment