python - 如何获取python的Internet Explorer地址栏

标签 python internet-explorer pywin32

我需要获取 Internet Explorer 地址栏。如何获取 python 的地址栏 url? (我需要第二部分其他浏览器抓取地址栏,但 Internet Explorer 是紧急的)。

谢谢。

最佳答案

以下对我有用。

from win32com.client import Dispatch

SHELL = Dispatch("Shell.Application")

def get_ie(shell):
    for win in shell.Windows():
        if win.Name == "Windows Internet Explorer":
            return win
    return None

def main():
    ie = get_ie(SHELL)
    if ie:
        print ie.LocationURL
    else:
        print "no ie window"

if __name__ == '__main__':
    main()

我尝试使用 Dispatch('InternetExplorer.Application') 连接到当前 IE 窗口,但它总是会创建一个新窗口。代码会更简单。

# This doesn't work
from win32com.client import Dispatch

# This line will always create a new window
ie = Dispatch("InternetExplorer.Application")

print ie.LocationURL

关于python - 如何获取python的Internet Explorer地址栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2555905/

相关文章:

python - SQLAlchemy 中与数据库无关的 MAX() 函数

python - 在 django 中实现 hashid

python - 在 Django 中获取当前登录用户

python - 替代 psutil.Process(pid).name

python - 在带有 pywin32、win32job、CreateJobObject 函数的 python 中,如何为 name 参数传递 NULL?

python - SqlAlchemy - 按关系属性过滤

javascript - Struts 1 提交仅适用于 IE

javascript - IE 7 条件与 javascript

html - 不包括 IE 6/7 流量

python - 为什么这个有效的 Tkinter 代码与一些 PyWin32 混合时会崩溃?