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
| import xlrd import os,stat import urllib.request
def get_path(): path = os.path.abspath(__file__) path = os.path.dirname(path) return path print(get_path())
filedata = get_path()+'\\'+input("请输入xls文件名(无需后缀):")+'.xls' print(filedata) data = xlrd.open_workbook(filedata)
file_path = get_path()+'\\'+input("请输入文件保存的文件夹名字:")
ifyg = input('是否每个名字一个文件夹:(y/n)') table = data.sheets()[0] nrows = table.nrows ncols = table.ncols nameid = [] for i in range(ncols): if table.cell(0,i).value == '名字': name = i def download_img(img_url,file_path,file_name): if not os.path.exists(file_path): os.makedirs(file_path) suffix = os.path.splitext(img_url)[1] filename = os.path.join(file_path,file_name + suffix) urllib.request.urlretrieve(img_url,filename=filename) os.chmod(filename,stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) def zuih(id,phoname,link,file_path): if ifyg == 'y': file_paths = file_path+'\\'+id download_img(link,file_paths,phoname) else : phonames = id + phoname download_img(link,file_path,phonames) def get_link(i,name,nrows,table): for j in range(1,nrows): hyperlink_obj = table.hyperlink_map.get((j,i)) link = hyperlink_obj.url_or_path link = link.split('?')[0] id = table.cell(j,name).value print(id) print(link) zuih(id,phoname,link,file_path) for i in range(ncols): values = table.cell(1,i).value if not isinstance(values,str): values = str(values) str1 = 'jpeg' if str1 in values: phoname = table.cell(0,i).value get_link(i,name,nrows,table)
|