简体   繁体   English

如何获取python的firefox地址栏url(pywin32)

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

i need grab to firefox address bar.我需要抓取到 Firefox 地址栏。 how to get address bar url for python ?如何获取python的地址栏网址? (i need second part other browsers chrome and safari grabbing address bar but firefox is urgently). (我需要第二部分其他浏览器 chrome 和 safari 抓取地址栏,但 firefox 是紧急的)。

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您将需要通过所有顶级窗口,并查看标题是否包含 firefox 或使用 spy++ 检查 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)

Also you can use this module to do most of such tasks http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html你也可以使用这个模块来完成大部分这样的任务http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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