def downjpgmutithread( filepathlist ): print("共有%d个文件需要下载"%len(filepathlist)) for file in filepathlist: print( file ) print("开始多线程下载") task_threads=[] #存储线程 count=1 for file in filepathlist: t= threading.Thread( target=downjpg,args=(file,"%d.jpg"%count)) count=count+1 task_threads.append(t) for task in task_threads: task.start() for task in task_threads: task.join() #等待所有线程结束 print("已经完成所有任务")
def downjpgmutithread( filepathlist ): print("共有%d个文件需要下载"%len(filepathlist)) for file in filepathlist: print( file ) print("开始多线程下载") task_threads=[] #存储线程 count=1 for file in filepathlist: t= threading.Thread( target=downjpg,args=(file,"%d.jpg"%count)) count=count+1 task_threads.append(t) for task in task_threads: task.start() for task in task_threads: task.join() #等待所有线程结束 print("线程结束")
class parserLinks( parser.HTMLParser): filelist=[] def handle_starttag(self,tag,attrs): if tag =='img': for name,value in attrs: if name =='src': print( value) self.filelist.append(value) #print( self.get_starttag_text()) def getfilelist(self): return self.filelist