如何获得火狐地址栏的网址为python(pywin32) [英] how to get firefox address bar url for python (pywin32)

查看:252
本文介绍了如何获得火狐地址栏的网址为python(pywin32)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要抓住Firefox的地址栏。如何获取地址栏的网址为Python? (我需要第二部分其他浏览器铬和狩猎抓地址栏,但火狐紧急)。

谢谢。

解决方案

你需要通过所有的顶级窗口,看看标题是否包含firefox或使用spy ++检查Firefox的窗口类,然后通过所有的子窗口查找URL,作为一个起点做这样的事情

  import win32gui 

def enumerationCallaback(hwnd,results):
text = win32gui.GetWindowText(hwnd)
如果text.find(Mozilla Firefox)> = 0:
results.append((hwnd,text))

mywindows = $]
win32gui.EnumWindows(enumerationCallaback,mywindows)
for win,mywindows中的文本:
打印文本
$ b $ def recurseChildWindow(hwnd,results):
win32gui.EnumChildWindows(hwnd,recurseChildWindow,结果)
print hwnd
#使用SendMessage尝试获取窗口类,文本等,看看它是我们想要的

mychildren = []
recurseChildWindow(mywindows [0] [0],mychildren)

你也可以使用这个模块完成大部分这样的任务
http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html


i need grab to firefox address bar. how to get address bar url for python ? (i need second part other browsers chrome and safari grabbing address bar but firefox is urgently).

Thanks.

解决方案

You will need to go thru all top windows, and see if title contains firefox or check window class of firefox using spy++, then go thru all child windows to find URL, as a starting point do something like this

import win32gui

def enumerationCallaback(hwnd, results):
    text = win32gui.GetWindowText(hwnd)
    if text.find("Mozilla Firefox") >= 0:
        results.append((hwnd, text))

mywindows = []    
win32gui.EnumWindows(enumerationCallaback, mywindows)
for win, text in mywindows:
    print text

def recurseChildWindow(hwnd, results):
    win32gui.EnumChildWindows(hwnd, recurseChildWindow, results)
    print hwnd
    # try to get window class, text etc using SendMessage and see if it is what we want

mychildren = []
recurseChildWindow(mywindows[0][0], mychildren)

Also you can use this module to do most of such tasks http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

这篇关于如何获得火狐地址栏的网址为python(pywin32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆