Python3根据URL下载图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/abstract_js/article/details/89041395

代码如下:
import urllib
import urllib.request

def get_image(url,stuNum):
try:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
get_img = response.read()
with open(‘D:\stuphoto\’+str(stuNum)+’.jpg’,‘wb’) as fp:
fp.write(get_img)
print(‘图片下载完成’)
except:
print(‘访问空’)

stuNum =
url = ‘’
for i in range(500):
stuNum = stuNum+1
get_image(url+str(stuNum)+’.JPG’,stuNum)

展开阅读全文

没有更多推荐了,返回首页