1——我想要PPT模板
2——Python来实现
# author:
# datetime:2022/6/22 19:30周三
# software: PyCharm
"""
文件说明:
"""
import requests
from lxml import etree
import re
import os
url = 'https://www.1ppt.com/xiazai/jianli/'
ua = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
res = requests.get(url, headers=ua)
res.encoding = 'gbk'
response = etree.HTML(res.text)
# 1 获取第一级的标题和对应的链接
link1 = response.xpath('//ul[@class="tplist"]/li/a/@href')
title1 = response.xpath('//ul[@class="tplist"]//@alt')
d = dict(zip(title1, link1))
for n1, url1 in d.items():
url1 = 'https://www.1ppt.com' + url1
res2 = requests.get(url1, headers=ua)
res2.encoding = 'gbk'
data = etree.HTML(res2.text)
data = data.xpath('//ul[@class="downurllist"]/li/a/@href')
url2 = 'https://www.1ppt.com' + data[0]
res3 = requests.get(url2, headers=ua)
data3 = etree.HTML(res3.text).xpath('//ul[@class="downloadlist"]/li/a/@href')
# print(data3[0])
path1 = 'c://mmm/1PPT模板/'
if not os.path.exists(path1):
os.mkdir(path1)
f_data = requests.get(data3[0], headers=ua).content
# print(f_data)
suffix = data3[0].split('.')[-1]
path1 = path1 + n1 + '.' + suffix
print(path1)
with open(path1, 'wb') as ff:
ff.write(f_data)