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

白昼怎懂夜的黑 提交于 2019-12-11 09:59:41

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/2598404/how-to-get-firefox-address-bar-url-for-python-pywin32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!