python批量下载链接图片
import urllib
import urllib.request
import pandas as pd
def get_image(url, filename):
try:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
get_img = response.read()
filepath = r'E:\家居图片\{}.png'.format(filename)
with open(filepath,'wb') as fp:
fp.write(get_img)
print('图片下载完')
except:
print('访问空')
data = pd.read_excel(r'E:\家居图片\device_info.xlsx')
for i in range(len(data)):
deviceid = data.ix[i,'device_type_id']
devicename = data.ix[i,'device_type_name']
filename = str(deviceid)+'_'+devicename
url = '{}.png'.format(deviceid)
get_image(url, filename)