爬虫-简单爬取视频

Posted xiaowangba9494

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬虫-简单爬取视频相关的知识,希望对你有一定的参考价值。

 

1、请求Headers里

技术图片

 

URL请求地址,分析得出加载视频个数

1625830,1625746,等等为加载更多视频过滤条件

 

2、去除后缀,拿原始链接可以请求数据

技术图片

分析得知start=0 为第一个视频

 

3、查看源代码,下面为真实数据请求地址

技术图片

 

 

4、代码

# 获取视频
import re
res = requests.get(https://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=1&start=0)

reg_text =<a href="(.*?)" class="vervideo-lilink actplay">
obj = re.findall(reg_text,res.text)
print(obj) # ‘video_1626266‘列表集合

for url in obj:
    url = https://www.pearvideo.com/+url
    res1 = requests.get(url)
    # 获取真实的视频资源请求地址
    obj1 = re.findall(srcUrl="(.*?)",res1.text)
    print(obj1) # [‘https://video.pearvideo.com/mp4/adshort/20191125/cont-1626232-14630171_adpkg-ad_hd.mp4‘]
    name = obj1[0].rsplit(/,1)[1]
    print(name) # cont-1626232-14630171_adpkg-ad_hd.mp4
    # 发送请求资源
    res2 = requests.get(obj1[0])
    with open(name,wb)as f:
        # 流式保存
        for line in res2.iter_content():
            f.write(line)

 

以上是关于爬虫-简单爬取视频的主要内容,如果未能解决你的问题,请参考以下文章

优酷视频信息的简单爬取

Python爬虫腾讯视频m3u8格式分析爬取(附源码,高清无水印)

scrapy主动退出爬虫的代码片段(python3)

一个简单的爬取b站up下所有视频的所有评论信息的爬虫

python爬虫:爬取网站视频

python爬虫:爬取网站视频