1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import shutil import requests
def zip_dir(basename,format,root_dir): shutil.make_archive(base_name=basename,format=format,root_dir=root_dir)
def getCookies(cookie_str): cookie_items = cookie_str.split(';') cookie_dict = {} for item in cookie_items: key, value = item.strip().split('=', 1) cookie_dict[key] = value return cookie_dict
def getFiles(cookies,fileid) : headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Host': 'portal.jictrust.cn', 'Pragma': 'no-cache', } params = ( ('download', '1'), ('fileid', fileid), ) response = requests.get('http://id/weaver/weaver.file.FileDownload', headers=headers, params=params, cookies=cookies) return(response)
def downloadFiles(response,username,depart): path = r'C:\Users\admin\Documents\workspace\下载泛微文件夹\download\{}_{}.pdf'.format(username,depart) with open(path ,'wb') as f: f.write(response.content) print('文件下载完成')
if __name__ == '__main__': cookies = '''复制的cookies信息粘贴到这里''' allMsg = [("姓名1","部门1",1234),("姓名2","部门2",5678)] cookies = getCookies(cookies) for msg in allMsg: response = getFiles(cookies,msg[2]) downloadFiles(response,msg[0],msg[1]) basename = r'C:\Users\admin\Documents\workspace\下载泛微文件夹\身份证扫描件导出' root_dir = r'C:\Users\admin\Documents\workspace\下载泛微文件夹\download' zip_dir(basename=basename,format='zip',root_dir=root_dir)
|