Python script simulation Browser

Source: Internet
Author: User

(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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.