2010-04-08 27 views
1

我需要抓取firefox地址栏。如何获取python的地址栏url? (我需要第二部分其他浏览器铬和Safari浏览器抓住地址栏,但Firefox是迫切)。如何获取python的python地址栏url(pywin32)

谢谢。

+0

您可以发送的Alt-d,按Ctrl-C最多,从剪贴板获得。 – YOU 2010-04-08 08:31:19

+0

我喜欢互联网内容过滤器。我需要外部程序调用和检查。 – 2010-04-08 08:50:48

回答

3

你需要去通所有顶层窗口,看看标题包含Firefox或使用间谍检查的Firefox的窗口类++,那么我们将向您所有子窗口找到URL,为出发点做这样的事情

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) 

您也可以使用此模块来执行这样的任务 http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

+0

+1非常好,谢谢。 – systempuntoout 2010-04-08 10:11:19