如果在运行如上代码前,先打开一个 ie 浏览器,就正常运行,不会报错。
但是,如果不事前打开一个 ie 浏览器,直接运行如上代码,就会报错。
请大家看看是什么原因?
怎么弄好呢?
环境:
windows7 64位
python 2.7.12 32位
代码:
from PAM30 import PAMIE
def d():
ie = PAMIE()
ie.navigate('http://pamie.sourceforge.net/pamieform.html')
报错信息如下:
Traceback (most recent call last): File "D:/jianguoyun/pythonProgrames/myModule/test/pamieTest/pamie-f.py", line 37, in <module> d() File "D:/jianguoyun/pythonProgrames/myModule/test/pamieTest/pamie-f.py", line 9, in d ie = PAMIE() File "D:\jianguoyun\pythonProgrames\myModule\PAM30.py", line 68, in __init__ self._ie = win32com.client.dynamic.Dispatch('InternetExplorer.Application') File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 127, in Dispatch IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221164, '\xc3\xbb\xd3\xd0\xd7\xa2\xb2\xe1\xc0\xe0', None, None)
看来是找不到InternetExplorer.Application这个类,预计是你的IE版本不为默认的IE8