【Python原创】requests-人人视频下载爬虫1.0
本帖最后由 Pastwill 于 2022-2-11 22:38 编辑一.环境
windwos 10 Python 3.6 x86
二.调用模块
import requests
import json
import re
import os
安装命令
pip installrequests
pip install json
pip install re
pip install os
三.代码
#windows 10 Python 3.6 x86
import requests
import json
import re
import os
headers = {
'Referer':'https://m.rr.tv/',#全局设置
'User-Agent':'Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36'
}
ep_list =[]
vod_list = []
def get_vod(url):
response = requests.get(url = url,headers = headers)#请求url
ep= re.compile(r'sid:"(.*?)",')#提取ep链接
ep_list = re.findall(ep,response.text)
vod= re.compile(r'data:\[{id:(.*?),title:"')#提取vod链接
vod_list = re.findall(vod,response.text)
vod= re.compile(r',title:"(.*?)",desc:"')#提取视频标题
vod_name = re.findall(vod,response.text)
ep = 1
os.mkdir('./'+vod_name)#创建视频保存目录
for i in ep_list:
print("开始下载"+vod_name+"第"+str(ep)+"集")
url ="https://web-api.rr.tv/web/drama/play?webChannel=M_STATION&dramaId="+vod_list+"&episodeId="+i+"&2-7-17xx"#拼接地址
response = requests.get(url = url,headers = headers)#下载请求
r = requests.get(str(json.loads(response.text)['data']['url']), stream=True)#解析出下载链接并发起下载请求
f = open("./"+vod_name+"/第"+str(ep)+"集.MP4", "wb")#保存视频
for chunk in r.iter_content(chunk_size=512):
if chunk:
f.write(chunk)
ep = ep+1
if __name__ == '__main__':
url='https://m.rr.tv/detail/xxxxxx?snum=1&episode=1'#目标视频链接
get_vod(url)
谢谢大佬分享!!!建议搞成多线程,不然好慢!! gusong125 发表于 2022-2-10 15:40
谢谢大佬分享!!!建议搞成多线程,不然好慢!!
有时间会更新的
页:
[1]