Python uses win32com in Baidu space to insert HTML element example _python

Source: Internet
Author: User

Copy Code code as follows:

From win32com.client import Dispatchex
Import time
Ie=dispatchex ("Internetexplorer.application")

Ie. Navigate ("http://hi.baidu.com/mirguest/creat/blog/")
Ie. Visible=1
While IE. Busy:
Time.sleep (1)

Body=ie. Document.body
# header
For I in Body.getelementsbytagname ("Input"):
If Str (i.getattribute ("id")) = = "Spblogtitle":
Print "Find title"
I.value= "Autocreatedbypython"
Break

# Editor
For I in Body.getelementsbytagname ("iframe"):
Print "Find IFrame"
If Str (i.getattribute ("id")) = = "Tangram_editor_iframe_tangram__1":
Print "Find"
Break
Iframe=i
Iframe.click ()
Sondoc=iframe.contentwindow.document;
Print Sondoc
Sonbody=sondoc.body
Print Sonbody
For II in Sonbody.getelementsbytagname ("P"):
Print "Find P"
Ii.innerhtml= "Hello,my A-try"
Tmp=sondoc.createelement ("div")
Tmp.innerhtml= "Bye"
Sonbody.insertbefore (TMP,II)

Tmphtml= "<div>hello 2</div>"
Sonbody.insertadjacenthtml ("BeforeEnd", tmphtml)
'''
Editor.getcontenthtml
'''

# submit
For I in Body.getelementsbytagname ("div"):
If Str (i.getattribute ("id")) = = "Btn-box":
Print "Find button"
Break

Btnbox=i
J=btnbox.childnodes (0)
J.click ()

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.