您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

5b51 2022/1/14 8:17:36 python 字数 2535 阅读 380 来源 www.jb51.cc/python

复制代码代码如下:fromwin32com.clientimportDispatchEximporttimeie=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()

总结

以上是编程之家为你收集整理的python使用win32com在百度空间插入html元素示例全部内容,希望文章能够帮你解决python使用win32com在百度空间插入html元素示例所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶