This article describes how to insert html elements in Baidu Space using win32com in python.
The 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 ("p ")
Tmp. innerHTML = "bye"
Sonbody. insertBefore (tmp, ii)
TmpHTML ="
Hello 2
"
Sonbody. insertAdjacentHTML ("beforeEnd", tmpHTML)
'''
Editor. getContentHTML
'''
# Submit
For I in body. getElementsByTagName ("p "):
If str (I. getAttribute ("id") = "btn-box ":
Print "Find button"
Break
Btnbox = I
J = btnbox. childNodes (0)
J. click ()