python调用ie抓取网页里的图片并保存,,import win32
文章由Byrx.net分享于2019-03-23 10:03:43
python调用ie抓取网页里的图片并保存,,import win32
import win32com.client,time,win32inet,win32file,osclass ImgDownloader: def __init__(self,url,dir): self.__dir=dir self.__ie=win32com.client.Dispatch('InternetExplorer.Application.1') self.__ie.Navigate(url) self.__ie.Visible = 1 self.__wait__() def __wait__(self): while self.__ie.Busy: time.sleep(0.5) def start(self): self.__wait__() imgs=self.__ie.Document.getElementsByTagName('img') for i in range(imgs.length): try: cachInfo=win32inet.GetUrlCacheEntryInfo(imgs[i].src) if cachInfo: path=cachInfo['LocalFileName'] pathinfo=path.split('\\') pathinfo.reverse() filename=('[%d]' % i) + pathinfo[0] win32file.CopyFile(path,os.path.join(self.__dir,filename),True) except: pass def close(self): self.__ie.Quit()if __name__=='__main__': d=ImgDownloader('http://www.sharejs.com','E:\\temp\\') d.start() d.close()
相关内容
- python版的快速排序算法代码,python排序算法,def qsort(L
- python自动zip压缩目录,pythonzip压缩目录,# Hello, thi
- python循环中使用continue语句代码片段,,#!/usr/bin/p
- 归并排序python实现代码,归并排序python,def mergesor
- bootstrapping and forward curve生成python范例,,## Descripti
- python编写的linux下使用的xcopy代码,pythonxcopy,#!/usr/bin/
- python实现的矩阵乘法,python矩阵乘法,def matrixMu
- python修改文件名、目录名,python修改文件名,os.rename("
- python 给数组按片赋值,,inventory =
- python按单词翻转字符串,python翻转字符串,def reverseW
评论关闭