Copy CodeThe code is 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 First Try"
Tmp=sondoc.createelement ("div")
Tmp.innerhtml= "Bye"
Sonbody.insertbefore (TMP,II)
Tmphtml= "Hello 2"
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 ()