当前位置: 移动技术网 > IT编程>脚本编程>Python > python使用win32com在百度空间插入html元素示例

python使用win32com在百度空间插入html元素示例

2019年04月01日  | 移动技术网IT编程  | 我要评论

濠江岁月上,汽车站标志,苍井空开b图片

复制代码 代码如下:

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="<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()

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网