脚本专栏 
首页 > 脚本专栏 > 浏览文章

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

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

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

上一篇:python文件读写并使用mysql批量插入示例分享(python操作mysql)
下一篇:python实现bitmap数据结构详解
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网