# 本文仅供学习参考。 # https://www.ypppt.com/article/2018/4692.html 点击图片链接 # https://www.ypppt.com/p/d.php?aid=4692 点击下载链接 # https://down.ypppt.com/uploads/soft/180301/1-1P301092632.zip 下载地址 # 提示证书错误 #加载模块 import requests #去除运行的警告 import urllib3 #正则表达式 import re urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) #初始化变量 page = 1 #循环下载 while True: #第一页和第二页链接不一样 if page == 1: url = 'https://www.ypppts.com/moban/' else: url = f'https://www.ypppts.com/moban/list-{page}.html' print(page) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36' } res = requests.get(url, headers=headers) res.encoding = 'utf-8' #找到id和名字 ppt_list = re.findall('<a href="/article/.*?/(.*?).html" class="p-title" target="_blank">(.*?)</a>', res.text) for pptlist in ppt_list: pptid = pptlist[0] pptname = pptlist[1] #合成网址 url = 'https://www.ypppt.com/p/d.php?aid=' + pptid res = requests.get(url, headers=headers, verify=False) #找到下载网址 down_url = re.findall('<a href="(.*?)">下载地址1</a>',res.text)[-1] downres =requests.get(down_url, headers=headers, verify=False) if 'pan.baidu' in down_url: continue open(f'PPT模板/{pptname}.{down_url.split(".")[-1]}','wb').write(downres.content) page += 1