import requests import re import os {% asset_img 1.png %}
if not os.path.exists("./qiutu"): os.mkdir("./qiutu") headers={"User-Ageent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74"} for i in range(1,6): url="https://www.qiushibaike.com/imgrank/page/{0}".format(i) page_text=requests.get(url,headers=headers).text ex='<div class="thumb">.*?<img src="(.*?)" alt.*?</div>' src_list=re.findall(ex,page_text,re.S) for src in src_list: src="https:"+src img=requests.get(src,headers=headers).content img_name=src.split("/")[-1] img_path="./qiutu/"+img_name with open(img_path,"wb") as file: file.write(img) print(img_name,"下载完毕...")
|