python 은 win32com 으로 브 라 우 저 를 모 의 합 니 다.

1572 단어 python

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--># -*- 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)


좋은 웹페이지 즐겨찾기