Example of using win32com to insert html elements in Baidu Space in python

Source: Internet
Author: User
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 ()

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.