- 论坛徽章:
- 0
|
拿到了地址栏的句柄,可为啥传回来的不是地址栏的URL,请大虾指正
(py3.0+pywin32)
返回的结果是
<built-in method GetWindowText of PyCWnd object at 0x019A2B0C>
import ctypes
import win32ui
desktop=ctypes.windll.user32.GetDesktopWindow()
desktopp=ctypes.windll.user32.FindWindowW("IEFrame",None)
ctypes.windll.user32.CloseWindow(desktopp)
ctypes.windll.user32.ShowWindow(desktopp,3)
IEHandle=win32ui.FindWindowEx(desktopp,None,'WorkerW',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ReBarWindow32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBoxEx32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBox',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'Edit',None)
str_val=IEHandle.GetWindowText
print(str_val)
|
改了代码,还是出错,帮我看看啊
Traceback (most recent call last):
File "D:\My Documents\12.py", line 16, in <module>
nchars = win32gui.SendMessage(IEHandle,win32con.WM_GETTEXT,buf_size,buf)
TypeError: The object is not a PyHANDLE object
import ctypes
import win32ui
import win32gui
import win32con
desktop=ctypes.windll.user32.GetDesktopWindow()
desktopp=ctypes.windll.user32.FindWindowW("IEFrame",None)
ctypes.windll.user32.CloseWindow(desktopp)
ctypes.windll.user32.ShowWindow(desktopp,3)
IEHandle=win32ui.FindWindowEx(desktopp,None,'WorkerW',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ReBarWindow32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBoxEx32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBox',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'Edit',None)
buf_size=255
buf=win32gui.PyMakeBuffer(buf_size)
nchars = win32gui.SendMessage(IEHandle,win32con.WM_GETTEXT,buf_size,buf)
|
再改代码,但只拿到主窗口的标题的一个字,救救我把,还有一个问题,就是第二次运行就报内存不能为读的错误
>>>
50
获
>>>
import ctypes
import win32ui
import win32gui
import win32con
desktop=ctypes.windll.user32.GetDesktopWindow()
desktopp=ctypes.windll.user32.FindWindowW("IEFrame",None)
ctypes.windll.user32.CloseWindow(desktopp)
ctypes.windll.user32.ShowWindow(desktopp,3)
IEHandle=win32ui.FindWindowEx(desktopp,None,'WorkerW',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ReBarWindow32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBoxEx32',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'ComboBox',None)
IEHandle=win32ui.FindWindowEx(IEHandle,None,'Edit',None)
buf_size=255
buf='\n'
nchars = win32gui.SendMessage(desktopp,win32con.WM_GETTEXT,buf_size,buf)
print(nchars)
print(buf)
|
[ 本帖最后由 我不是老手 于 2009-5-25 20:48 编辑 ] |
|