[英]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.