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

[导入][python]使用python确定已打开的ie窗口

前面控制ie都是新建一个ie。而昨天看了python cookbook,使用python也可以确定已存在的ie窗口。

比如我已经有个窗口,URL为http://blog.renren.com/blog/0/addBlog

然后为了确定这个ie,我们这样使用:

# -*- coding:utf-8 -*-
from win32com.client import Dispatch
ShellWindowsCLSID = '{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
ShellWindows = Dispatch(ShellWindowsCLSID)
print '%d instances of IE' % len(ShellWindows)
print
for shellwindow in ShellWindows :
    print shellwindow.LocationName
    print shellwindow.LocationURL
    print
    if shellwindow.LocationURL=="http://blog.renren.com/blog/0/addBlog":
        print "Find"
        break

ie=shellwindow
doc=ie.Document
body=doc.body
for i in body.getElementsByTagName("input"):
    if str(i.getAttribute("id"))=="title":
        print "Find title"
        i.value="AutoCreatedByPython"
        break

其实这个我也不太懂,只知道 ShellWindowsCLSID 其实在注册表中对应的。这个找到的是全部的ie窗口。

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

posted on 2011-02-10 11:52 mirguest 阅读(627) 评论(0)  编辑 收藏 引用


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