Python 实现输入名字自动批量下载图片
【摘要】
import requests
import os
import re
word=input("请输入你要下载的图片:")
if not os.path.exists(word):
os.mkd...
import requests
import os
import re
word=input("请输入你要下载的图片:")
if not os.path.exists(word):
os.mkdir(word)
url="https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word="+word+""
result=re.findall('"objURL":"(.*?)",',ret)
for i in result:
end=re.search('(.jpg|.png|.gif|.jpeg)$',i)#判断是否以该格式结尾
if end == None:
i=i+'.jpg'
try:
with open(word+'/%s'%i[-10:],'ab') as f:
img=requests.get(i,timeout=3)
f.write(img.content)
except Exception as e:
print(e)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
文章来源: blog.csdn.net,作者:考古学家lx,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_43582101/article/details/86480285
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)