国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

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

2020-02-23 05:11:42
字體:
來源:轉載
供稿:網友

代碼如下:
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()

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 栾川县| 姚安县| 客服| 开鲁县| 遂川县| 莱芜市| 花莲市| 万源市| 白河县| 彭山县| 治多县| 翼城县| 霍邱县| 阜新市| 库伦旗| 海晏县| 丘北县| 贺州市| 民勤县| 香河县| 岳西县| 个旧市| 曲松县| 安西县| 巢湖市| 罗定市| 油尖旺区| 隆安县| 万州区| 额敏县| 阿尔山市| 六安市| 红安县| 桂林市| 栾川县| 依兰县| 镇雄县| 新兴县| 淳化县| 邵武市| 贵南县|