简体   繁体   中英

how to get firefox address bar url for python (pywin32)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM