如何获得火狐地址栏的网址为python(pywin32) [英] how to get firefox address bar url for python (pywin32)
问题描述
谢谢。
你需要通过所有的顶级窗口,看看标题是否包含firefox或使用spy ++检查Firefox的窗口类,然后通过所有的子窗口查找URL,作为一个起点做这样的事情
import win32gui
def enumerationCallaback(hwnd,results):
text = win32gui.GetWindowText(hwnd)
如果text.find(Mozilla Firefox)> = 0:
results.append((hwnd,text))
mywindows = $]
win32gui.EnumWindows(enumerationCallaback,mywindows)
for win,mywindows中的文本:
打印文本
$ b $ def recurseChildWindow(hwnd,results):
win32gui.EnumChildWindows(hwnd,recurseChildWindow,结果)
print hwnd
#使用SendMessage尝试获取窗口类,文本等,看看它是我们想要的
mychildren = []
recurseChildWindow(mywindows [0] [0],mychildren)
你也可以使用这个模块完成大部分这样的任务
http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html
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
这篇关于如何获得火狐地址栏的网址为python(pywin32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!