2019-06-27
阅读量:
818
利用python爬虫下载单个图片?
问、利用python爬虫下载单个图片?
答:
from hashlib import md5
import os
os.chdir('C:\\Users\\chen')
url='http://p3-tt.byteimg.com/large/pgc-image/fe1f67006cc14f88bcb2f616bb3419fb'
#保存图片
title=html['data'][1]['title']
resp = requests.get(url)#获取图片内容
img_path = 'img' + os.path.sep + title #os.path.sep,分隔符\\
os.makedirs(img_path)
file_path = img_path + os.path.sep + '{file_name}.{file_suffix}'.format(
file_name=md5(resp.content).hexdigest(),
file_suffix='jpg')
with open(file_path, 'wb') as f:
f.write(resp.content)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
3条评论