如果在執行如上程式碼前,先開啟一個 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
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