Python:检查 IE 状态时出错
请帮助我使用 Python 2.6 和 win32com。
我是 Python 新手,我遇到了错误 当我启动下一个程序时:
import pywintypes
from win32com.client import Dispatch
from time import sleep
ie = Dispatch("InternetExplorer.Application")
ie.visible=1
url='hotfile.com'
ie.navigate(url)
while ie.ReadyState !=4:
sleep(1)
print 'OK'
..........................
Error message:
while ie.ReadyState !=4:
...
pywintypes.com_error:
(-2147023179, 'Unknown interface.', None, None)
..........................
但是当我将 url 更改为“yahoo.com”时 - 没有错误。
检查 ReadyState 的结果如何可能依赖于 url?
Please, help me with Python 2.6 and win32com.
I'm a newbie to Python and I got error
when I start the next program:
import pywintypes
from win32com.client import Dispatch
from time import sleep
ie = Dispatch("InternetExplorer.Application")
ie.visible=1
url='hotfile.com'
ie.navigate(url)
while ie.ReadyState !=4:
sleep(1)
print 'OK'
..........................
Error message:
while ie.ReadyState !=4:
...
pywintypes.com_error:
(-2147023179, 'Unknown interface.', None, None)
..........................
But when I change url to, for example, 'yahoo.com' -
there are no errors.
How can result of checking ReadyState may be dependant on url??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
睡眠技巧不适用于 IE。实际上,您需要在等待时发送消息。顺便说一句,我认为线程不会起作用,因为 IE 讨厌不在 GUI 线程中。
这是一个基于 ctypes 的消息泵,通过它我能够获得 4 ReadyState对于“hotfile.com”和“yahoo.com”。它提取队列中当前的所有消息,并在运行检查之前对其进行处理。
(是的,这确实很麻烦,但是您可以将其放入“pump_messages”函数中,这样您至少不必查看它!)
The sleep trick won't work with IE. You actually need to pump messages while you wait. I don't think a thread will work, by the way, because IE hates to not be in the GUI thread.
Here's a ctypes-based message pump, with which I was able to get a 4 ReadyState for "hotfile.com" and "yahoo.com". It pulls all the messages currently on the queue, and processes them before running the check.
(Yes, this is pretty hairy, but you can tuck this away into a "pump_messages" function so you at least don't have to look at it!)