import re
import requests
import os
if not os.path.exists('./qiutuLibs'):
os.mkdir('./qiutuLibs')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
}
url = 'https://photo.xitek.com/style/2'
page_text = requests.get(url = url,headers=headers).text
e ='<a class="card-img-top" .*?<img src="(.*?)" .*?'
img_src = re.findall(e,page_text,re.S)
for src in img_src:
src = 'https:' + src
image_date = requests.get(url=src, headers=headers).content
image_name = src.split('/')[-1]
imgPath = './qiutuLibs/'+image_name
with open(imgPath,'wb')as fp:
fp.write(image_date)
print(image_name,"下载成功")
上面的代码,我进行了多次的尝试,可以成功爬取,但爬取下来的图片打不开会显示
望求答疑