# -*- coding:UTF-8 -*-
#!/user/bin/env python
'''
Created on 2010-9-1
@author: chenzehe
'''
import win32com.client
from time import sleep
loginurl='http://passport.cnblogs.com/login.aspx'
loginouturl='http://passport.cnblogs.com/logout.aspx'
username='XXX'
password='XXX'
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 0
ie.Navigate(loginurl)
state = ie.ReadyState
print "打開登陸頁面"
while 1:
state = ie.ReadyState
if state ==4:
break
sleep(1)
print "頁面載入完畢,輸入用戶名密碼"
state = None
ie.Document.getElementById("tbUserName").value=username
ie.Document.getElementById("tbPassword").value=password
ie.Document.getElementById("btnLogin").click()
while 1:
state = ie.ReadyState
print state
if state ==4 and str(ie.LocationURL) == "http://home.cnblogs.com/":
break
sleep(1)
print "登陸成功"
print '你的暱稱是:'
print ie.Document.getElementById('lnk_current_user').title
#博客園只能登錄一次,註銷
print '註銷!'
ie.Navigate(loginouturl)
轉自:http://www.cnblogs.com/chenzehe/archive/2010/09/01/1814397.html