2010-04-08 26 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