python使用win32com在百度空间插入html元素示例
fromwin32com.clientimportDispatchEx
importtime
ie=DispatchEx("InternetExplorer.Application")
ie.Navigate("http://hi.baidu.com/mirguest/creat/blog/")
ie.Visible=1
whileie.Busy:
time.sleep(1)
body=ie.Document.body
#header
foriinbody.getElementsByTagName("input"):
ifstr(i.getAttribute("id"))=="spBlogTitle":
print"Findtitle"
i.value="AutoCreatedByPython"
break
#editor
foriinbody.getElementsByTagName("iframe"):
print"Findiframe"
ifstr(i.getAttribute("id"))=="tangram_editor_iframe_TANGRAM__1":
print"Find"
break
iframe=i
iframe.click()
sondoc=iframe.contentWindow.Document;
printsondoc
sonbody=sondoc.body
printsonbody
foriiinsonbody.getElementsByTagName("p"):
print"Findp"
ii.innerHTML="hello,myfirsttry"
tmp=sondoc.createElement("div")
tmp.innerHTML="bye"
sonbody.insertBefore(tmp,ii)
tmpHTML="<div>hello2</div>"
sonbody.insertAdjacentHTML("beforeEnd",tmpHTML)
"""
editor.getContentHTML
"""
#submit
foriinbody.getElementsByTagName("div"):
ifstr(i.getAttribute("id"))=="btn-box":
print"Findbutton"
break
btnbox=i
j=btnbox.childNodes(0)
j.click()
相关文章
- Python 上下文管理及 with 语句的实用技巧
- python中dtype什么意思_NumPy Python中的数据类型对象(dtype)
- json转字符串 python_Python读取json
- 【说站】python如何追写内容
- 【说站】python二分支结构如何理解
- 【说站】python二项分布的概率使用
- Python实现自动回复_python 微信机器人
- Python标识符的命名规则,下列哪些是对的?_python标识符不能使用关键字
- python zipfile_Python 学习入门(16)—— zipfile
- python进程模块
- allowMultiQueries=true_python的list用法
- python递归函数讲解_Python递归函数实例讲解
- 搭建python开发环境-c++教程 如何搭建Python开发环境?
- 如何下载安装Python解释器?Python解释器安装教程步骤图解
- VScode 给python文件添加作者、日期、描述等信息
- Python __call__()方法(详解版)
- python在线抓取百度词典的翻译结果翻译单词详解编程语言
- Linux下使用Python开发体验之旅(linux使用python)
- 3 个到今天仍然有用的 Python 3.2 特性
- 从 Python 连接到 MySQL:实现更多强大的数据库应用(python和mysql)
- Python中使用MySQL数据库的操作技巧(mysql_python)
- Python实现删除Android工程中的冗余字符串