簡體   English   中英

如何獲取python的firefox地址欄url(pywin32)

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

我需要抓取到 Firefox 地址欄。 如何獲取python的地址欄網址? (我需要第二部分其他瀏覽器 chrome 和 safari 抓取地址欄,但 firefox 是緊急的)。

謝謝。

您將需要通過所有頂級窗口,並查看標題是否包含 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)

你也可以使用這個模塊來完成大部分這樣的任務http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM