自己写了玩的一个小脚本,百度图片下载
import re
import os
import requests
import hashlib
def dowmloadPic(html, keyword):
pic_url = re.findall('"objURL":"(.*?)",', html, re.S)
if len(pic_url) < 1:
return 1
i = 0
for each in pic_url:
print(i + 1, end=',')
md5Str = hashlib.md5(each.encode("utf-8")).hexdigest()
# 抓去链接
oneStr = md5Str + ' ' + keyword + ' ' + each + '\n'
with open('downText.txt', 'a+') as f:
f.write(oneStr)
# 下载图片
# try:
# pic = requests.get(each, timeout=10)
# except requests.exceptions.ConnectionError:
# print('链接超时,跳过此操作')
# continue
#
# kz = os.path.splitext(each)[-1]
# photo = + keyword + '_