|
- import os
- import re
- import requests
- from lxml import etree
- if not os.path.exists('d:/糗事百科视频'):
- os.mkdir('d:/糗事百科视频')
- j = 1
- url = 'https://www.qiushibaike.com/video/'
- ua = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'}
- for i in range(1,14):
- if i == 1:
- url = 'https://www.qiushibaike.com/video/'
- else:
- url = f'https://www.qiushibaike.com/video/page/{i}/'
- #print(url)
- respon = requests.get(url=url,headers=ua).text
- jiexi = etree.HTML(respon)
- 视频地址 = jiexi.xpath('//div[@class = "article block untagged mb15 typs_recent"]//video/source/@src')
- #视频地址 = ['https:'+视频地址 for 视频地址 in 视频地址]
- 视频地址 = ['https:' + 视频地址 for 视频地址 in 视频地址]
- for 视频地址 in 视频地址:
- vediodate = requests.get(url=视频地址,headers=ua).content
- houzhui = 视频地址.split('.')[-1]
- add = 'd:/糗事百科视频/'+str(j)+'.'+houzhui
- j = j+1
- with open(add,'wb') as a:
- a.write(vediodate)
- print(add,'下载完成')
复制代码
|
|