随笔 - 41, 文章 - 8, 评论 - 8, 引用 - 0
数据加载中……

[导入][python]继续使用python操控ie(人人网)

搞了百度的文章自动发布,现在再搞搞人人网的。

但是人人网比较恶心,似乎很多元素都不支持。不过自己可以插入style。

我使用的是ie9,不知道大家其他版本的是否也能用。注意还要已登陆。

好了,直接贴代码:

from win32com.client import DispatchEx
import time
ie=DispatchEx("InternetExplorer.Application")

ie.Navigate("http://blog.renren.com/blog/0/addBlog")
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"))=="title":
        print "Find title"
        i.value="AutoCreatedByPython"
        break

# editor
for i in body.getElementsByTagName("iframe"):
    if str(i.getAttribute("id"))=="editor_ifr":
        print "Find Editor"
        break
iframe=i
childdoc=iframe.contentWindow.Document

childbody=childdoc.body
tmpHTML="<p style='float:left;border:1px black solid;margin:10px;padding:10px;width:280px;background:#c1c1c1;'>"
tmpHTML+="hello"*100
tmpHTML+="</p>"
tmpHTML+=tmpHTML
tmpHTML+="<h2>Header</h2>"
childbody.insertAdjacentHTML("beforeEnd",tmpHTML)

# submit
for i in body.getElementsByTagName("input"):
    if str(i.getAttribute("id"))=="editorFormBtn":
        print "Find button"
        i.click()
        break

# exit
ie.quit()

阅读全文
类别:Python 查看评论
文章来源:http://hi.baidu.com/mirguest/blog/item/ac16916202b7cdcc8db10d38.html

posted on 2011-02-07 12:22 mirguest 阅读(356) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理