defget_list(self): req = requests.get(url=self.base_url,headers=self.headers,params=self.params) # 数据转换 data = req.json() print() try : if data['data']['list'] : data = data['data']['list'] return data except : print("no data find") returnNone
defget_img_list(self): res = self.get_list() imgUrls = [] if res : for e in res : if e['picUrl']: urls = e['picUrl'] imgUrls += urls
print("图片列表为:",imgUrls) return imgUrls
defget_excel_data(self): res = self.get_list() excel_list =[] if res : for e in res: cell = [e['addTime'],e['brief'],e['columnName'],e['details'],e['name'],e['updateTime']] excel_list.append(cell)
print(excel_list) return excel_list
defdownload_img(self,name): # 判断是否有文件夹 ifnot os.path.exists(name): os.mkdir(name) print("文件夹{}创建成功".format(name)) imgList = self.get_img_list() names =0 if imgList : for i in imgList: names += 1 threading.Thread(target=self.download, args=(names, i,name)).start()
defdownload(self,name,image_url,path): print('开始下载:', name) content = requests.get(image_url).content path = '%s/%s.jpg' % (path, name) with open(path, 'wb') as f: f.write(content) print('下载完成', name)