1.第一步下拉展示的图片越多下载得越多
2.第二步右键保存
3.读取保存的html,其中
根据data-objurl获取的下载地址,其图片质量相对来说比较清晰
代码如下:
# -*- coding:utf-8 -*-
import re
import requests
def dowmloadPic(html, keyword):
pic_url = re.findall('data-objurl=\"(.*?)\"', html, re.S)
print(pic_url)
num=len(pic_url)
for i in range(num):
if pic_url[i]:
print('正在下载第' + str(i) + '张图片,图片地址:' + str(pic_url[i]))
try:
pic = requests.get(pic_url[i], timeout=10)
except requests.exceptions.ConnectionError:
print('【错误】当前图片无法下载')
continue
dir = '../images/' + keyword + '_' + str(i) + '.jpg'
fp = open(dir, 'wb')
fp.write(pic.content)
fp.close()
if __name__ == '__main__':
"""
根据data-objurl获取的下载地址,其图片质量相对来说比较清晰
"""
word = "open_bank"
file = "开户许可证_百度图片搜索.html"
f = open(file, "r", encoding="utf-8")
asa = f.read()
dowmloadPic(asa, word)