找回密码
 立即注册
搜索
热搜: Excel discuz
查看: 1723|回复: 0

[项目代码] 批量下载PPT模板

[复制链接]

492

主题

7万

元宝

77万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
770449
发表于 2021-7-25 22:11:57 | 显示全部楼层 |阅读模式
我自己写的代码,还可以精简很多代码,目前还没有翻页的效果
  1. import os
  2. from lxml import etree
  3. import requests
  4. if not os.path.exists('d:/ppt1'):
  5.     os.mkdir('d:/ppt1')
  6. url = 'http://www.1ppt.com/moban/jianjie/'
  7. ua = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'}
  8. respon = requests.get(url= url,headers= ua)
  9. respon.encoding = 'gb2312'
  10. jiexi = etree.HTML(respon.text)
  11. lianjie = jiexi.xpath('//ul[@class="tplist"]/li/a/@href')
  12. listlianjie = []
  13. for i in lianjie:
  14.     lianjie = 'http://www.1ppt.com' + i
  15.     listlianjie.append(lianjie)
  16. name = jiexi.xpath('//ul[@class="tplist"]/li/a/img/@alt')
  17. #print(name)

  18. dwonlist = []
  19. for url in listlianjie:
  20.     respon = requests.get(url=url,headers=ua).text
  21.     jiexi = etree.HTML(respon)
  22.     downurl = jiexi.xpath('//ul[@class="downurllist"]/li/a/@href')
  23.     downurl = ['http://www.1ppt.com' + downurl for downurl in downurl]
  24.     #print(downurl[0])
  25.     respon = requests.get(url=downurl[0],headers=ua).text
  26.     jiexi = etree.HTML(respon)
  27.     downurl1 = jiexi.xpath('//li[@class="c1"]/a/@href')
  28.     for i in downurl1:
  29.         dwonlist.append(i)

  30. #print(dwonlist)
  31. zidian = dict(zip(name,dwonlist))
  32. for name,dwonlist in zidian.items():
  33.     houzhui = dwonlist.split('.')[-1]
  34.     add = 'd:/ppt1/' + name +'.'+houzhui
  35.     respon = requests.get(url=dwonlist,headers = ua).content
  36.     with open(add,'wb') as a:
  37.         a.write(respon)
  38.         print(name,'下载完成')
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|五花八门论坛 ( 豫ICP备15031300号-3 )

GMT+8, 2024-12-31 01:01 , Processed in 0.069876 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表