【Python爬虫】爬取ppt素材

代码:

"""
python爬取ppt素材
所需模块:request  re
爬取网站:https://www.ypppt.com
"""
import requests
import re
url='https://www.ypppt.com/moban/'
headers={
    
    
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.53'
}
response=requests.get(url=url,headers=headers)
response.encoding='utf-8'
#print(response.text)
ppt_info=re.findall('<a href="(.*?)" class="p-title" target="_blank">(.*?)</a>',response.text)
#print(ppt_info)
for index,title in ppt_info:
    ppt_id=index.split('/')[-1][:-5]
    index_url=f'https://www.ypppt.com/p/d.php?aid={
      
      ppt_id}'
    response_1=requests.get(index_url,headers)
    download_url=re.findall('<li><a href="(.*?)">下载地址1</a></li>',response_1.text)[0]
    ppt_content=requests.get(download_url,headers).content
    # with open('素材\\'+title+'.zip',mode='wb') as f:
    #     f.write(ppt_content)
    print(ppt_id,title)

结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_52049271/article/details/127171195