码迷,mamicode.com
首页 > 编程语言 > 详细

Python之爬虫-酷6视频

时间:2019-07-20 23:41:38      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:pre   技术   chm   image   mamicode   爬虫   contain   www   请求   

Python之爬虫-酷6视频

import re
import requests

"""
@author RansySun
@create 2019-07-20-19:00
"""
# 网站地址
response = requests.get('https://www.ku6.com/index')
data = response.text
"""
<div class="video-image-container">
                    <a class="video-image-warp" target="_blank" href="/video/detail?id=R24vWnh_XhAVchmEcqxVaElqM_o.">
                        <img src="https://rbv01.ku6.com/wifi/o_1dg1e86u616g42te1lhj13ncvptc"></a>
                </div>
"""
# 查找视频链接
result_list = re.findall('<a class="video-image-warp" target="_blank" href="(.*?)">', data)

count = 0
for result in result_list:
    
    # result = result.split(" ")[-1].split('"')[-2] # 单个视频爬
    # print(result)
    if result.startswith('/video'):
        result = f"https://www.ku6.com{result}"
        print(result)
        # 请求视频链接
        result_data = requests.get(result)

        video_data = result_data.text
#       flvURL: "https://rbv01.ku6.com/wifi/o_1dg1e86u6ugk18k69b43ut19kibkvs"
        # 查找视频播放链接
        video_url = re.findall('flvURL: "(.*?)"', video_data)

        for result_url in video_url:
 #          print(result_url)
            # videl_res_url = result_url.split('"')[1] 单个视频
#             print(videl_res_url)
            # 请求视频播放链接
            video_response = requests.get(result_url)
            # 获取视频编码
            video_data = video_response.content
#            # print(video_data)
            # 保存视频
            with open(f"{count}_video.mp4", "wb") as fw:
                fw.write(video_data)
                fw.flush()
                count += 1
                print("成功")


结果:

技术图片

技术图片

Python之爬虫-酷6视频

标签:pre   技术   chm   image   mamicode   爬虫   contain   www   请求   

原文地址:https://www.cnblogs.com/randysun/p/11219503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!