- 论坛徽章:
- 0
|
在http://www.cnblogs.com/flysun/archive/2009/06/16/1504278.html找了个程序,代码如下:
1import win32com.client,time,win32inet,win32file,os
2class ImgDownloader:
3 def __init__(self,url,dir):
4 self.__dir=dir
5 self.__ie=win32com.client.Dispatch('InternetExplorer.Application')
6 self.__ie.Navigate(url)
7 self.__wait__()
8
9 def __wait__(self):
10 while self.__ie.Busy:
11 time.sleep(0.1)
12
13 def start(self):
14 self.__wait__()
15 imgs=self.__ie.Document.getElementsByTagName('img')
16
17 for i in range(imgs.length):
18 try:
19 cachInfo=win32inet.GetUrlCacheEntryInfo(imgs.src)
20 if cachInfo:
21 path=cachInfo['LocalFileName']
22 pathinfo=path.split('\\')
23 pathinfo.reverse()
24 filename=('[%d]' % i) + pathinfo[0]
25
26 win32file.CopyFile(path,os.path.join(self.__dir,filename),True)
27 except:
28 pass
29 def close(self):
30 self.__ie.Quit()
31
32if __name__=='__main__':
33 d=ImgDownloader('http://image.baidu.com/i?ct=201326592&cl=2&lm=-1&tn=baiduimage&pv=&word=boy&z=0','c:\\temp\\')
34 d.start()
35 d.close()
在IDLE中运行的时候:
Traceback (most recent call last):
File "E:\catch.py", line 33, in <module>
d=ImgDownloader('http://www.hao123.com/','E:\\temp\\')
File "E:\catch.py", line 5, in __init__
self.__ie=win32com.client.Dispatch('InternetExplorer.Application')
File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147024893, '系统找不到指定的路径。', None, None)
请问如何解决问题?? |
|