(Occasionally, for fear of forgetting)
When a user opens a browser, clicks and other behaviors, and then obtains the results, the following methods I have used only depend on IE, but Firefox and other methods should also have corresponding call methods:
The idea is to call the COM component of IE and then perform Dom operations similar to Dom operations using JavaScript. The Demo code is as follows:
# Tianyalogin login address <br/> tianyalogin = "http://www.tianya.cn/" <br/> tianya_user = "XXXXX" <br/> tianya_pw = "XXXXX" </P> <p> IE = win32com. client. dispatch ("internetexplorer. application ") <br/> IE. visible = 0 <br/> # start logging on <br/> IE. navigate (tianyalogin) <br/> state = IE. readystate <br/> Print "Open login page" <br/> while 1: <br/> state = IE. readystate <br/> If State = 4: <br/> Break <br/> sleep (1) <br/> Print "the page is loaded, enter the username and password "<br/> state = none <br/> IE. document. getelementbyid ("text1 "). value = tianya_user <br/> IE. document. getelementbyid ("password1 "). value = tianya_pw <br/> IE. document. getelementbyid ("button1 "). click () </P> <p> while 1: <br/> state = IE. readystate <br/> Print state <br/> If State = 4 and STR (ie. locationurl) = "http: // <br/> cache.tianya.cn/index.htm": <br/> Break <br/> sleep (1) <br/> Print "Login successful" </P> <p>