免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4718 | 回复: 0
打印 上一主题 下一主题

获取IE地址栏的URL,请人帮忙看看要怎么改 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-25 18:01 |只看该作者 |倒序浏览
拿到了地址栏的句柄,可为啥传回来的不是地址栏的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 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP