获取网站的所有ppt模板

ppt下载

from bs4 import BeautifulSoup
import requests
import time
from threading import Thread

print("正在下载ppt")

#进入ppt下载主页
url = "https://www.1ppt.com/"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"
           ,"Referer": "https://www.1ppt.com/"
           }
response = requests.get(url=url,headers=headers)
response.encodings='utf-8'
# print(response.text)

#获取进入ppt模板网页的链接
html = BeautifulSoup(response.text,"html.parser")
col_nav = html.find(class_="col_nav i_nav clearfix").find_all("a")
list_a = list()

#遍历ppt下载链接
for i in col_nav:
    href = i.get("href")
    hrefs = "https://www.1ppt.com/" + href
    time.sleep(1)
#进入ppt模板
    response1 = requests.get(url=hrefs,headers=headers)
    # print(response1.text)
    html1 = BeautifulSoup(response1.text,"html.parser")
    a = html1.find(class_="tplist").find_all("a")
#遍历ppt模板里面的所有超链接
    for j in a:
#建立一个列表放a来去重
        href1 = j.get("href")
        a_href = "https://www.1ppt.com" + href1
        if a_href not in list_a:
            list_a.append(a_href)
            time.sleep(0.5)
            print(f"获取第{j}个网页")
# 遍历列表里面的链接
for i in list_a:
    print(f"下载第{i}个网页")
    reponse2 = requests.get(url=i)
    html2 = BeautifulSoup(reponse2.text,"html.parser")

    # 获取下载链接zip网页
    downurllist_a = html2.find(class_="downurllist").find_all("a")


    #点击进入第一PPT素材下载页面
    down_ppt = requests.get(url=downurllist_a)
    html2 = BeautifulSoup(down_ppt.text, 'html.parser')
    a1 = html2.find(class_='c1').find_all('a')
    for x in a1:
        href1 = x.get('href')
        down_zip_ppt = requests.get(url=href1)
    with open(i + ".zip",mode="wb") as f:
        f.write(down_zip_ppt.content)
  • ​ 其中User-AgentReferer进入到https://www.1ppt.com/中打开开发者工具
    • 点击网络
    • 点击Fetch/XMR中的唯一一个包复制他们两个的值即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值