python爬虫实现各视频网站vip付费电影下载
时间:2021-07-19 16:55:50
收藏:0
阅读:0
python爬虫实现各视频网站vip付费电影下载
使用解析网站解析视频播放地址:http://jx.618g.com/
爬取解析网站,获得视屏片段
cmd命令合成很多ts文件为完整的MP4视屏文件:copy /b *ts movie.mp4
可在cmd窗口下运行,需到文件目录下,也可使用bat文件运行
为提高下载速度,使用进程池的方式下载
import requests
from multiprocessing import Pool
from fake_useragent import UserAgent
import os
# 单线程方式
# def download():
# headers = {
# ‘User-Agent‘: UserAgent().chrome
# }
# i=0
# while True:
# base_url = ‘https://youku.cdn7-okzy.com/20191203/16033_b28cd947/1000k/hls/0d2d28c500600%04d.ts‘ % i
# response = requests.get(base_url, headers=headers)
# # print(response.status_code)
# if response.status_code == 404:
# print(‘下载完成‘)
# break
# else:
# with open(‘./video/{}‘.format(base_url[-10:]), ‘wb‘)as f:
# f.write(response.content)
# i+=1
#
#
# if __name__ == ‘__main__‘:
# download()
# 使用进程池方式下载(更快,cpu占用更多)
def download(i,n):
headers = {
‘User-Agent‘: UserAgent().chrome
}
base_url = ‘https://youku.cdn7-okzy.com/20191203/16033_b28cd947/1000k/hls/0d2d28c500600%04d.ts‘ % i
response = requests.get(base_url, headers=headers)
with open(‘./video/{}‘.format(base_url[-10:]), ‘wb‘)as f:
f.write(response.content)
if i % 10 == 0:
print(‘\r下载进度:‘+str((i/n)*100)[:4]+‘%‘, end=‘‘)
if __name__ == ‘__main__‘:
n = 2200
po = Pool(5) # 创建一个进程池,可以包含5个子进程
for i in range(0, n):
po.apply_async(download, args=(i,n)) # 将全部进程全部加到进程队列中去
po.close()
print(‘\r开始下载.....‘, end=‘‘)
po.join()
评论(0)