当前位置: 首页 > ds >正文

【爬虫】案例-获取cbh电影

以cupfox.in为例子:

 

 观察ts文件和m3u8文件,可以知道一个完整的视频是由多个ts文件组合,而m3u8则是记录所有ts文件信息的文本

 思路

1.先爬一个ts,测试能否观看

2.爬m3u8文件,通过正则分析出变化的部分

3.完整的把每个ts爬下来组合起来。

 

1.一个ts

import requestsurl = 'https://v.cdnlz3.com/20240802/25255_00ff1a4b/2000k/hls/819a23c20b1000173.ts'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', 'referer':'https://www.cupfox.in/'}
response = requests.get(url)print(response.status_code)with open('video.ts', 'wb') as f:f.write(response.content)

 

 2.观察m3u8文件内容

分析得出:819a23c20b1000(.*?).ts

 

 3.完整代码:


import re
import requests
import time
import random
def get_m3u8():'''获取m3u8文件'''url = 'https://v.cdnlz3.com/20240802/25255_00ff1a4b/2000k/hls/index.m3u8'resp = requests.get(url).text# print(resp)ts_list = re.findall('819a23c20b1000(.*?).ts', resp)return ts_list
def get_response(ts_list):for ts in ts_list:url = f'https://v.cdnlz3.com/20240802/25255_00ff1a4b/2000k/hls/819a23c20b1000{ts}.ts'headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', 'referer':'https://www.cupfox.in/'}response = requests.get(url, headers=headers)try:with open('video.ts', 'ab') as f:f.write(response.content)print(f'下载完成,{ts+1}/{len(ts_list)}')time.sleep(random.uniform(1, 2))except Exception as e:print('报错原因是',e)if __name__ == '__main__':'''关键词.m3u8,它是一个文本文件,里面包含了多个ts'''a = get_m3u8() # 通过分析得出   # ts_list = re.findall('819a23c20b10(.*?).ts)', resp)get_response(a)

成功拿到,时长正确:

http://www.xdnf.cn/news/3224.html

相关文章:

  • centos7 安装python3
  • Vue2+Vue3学习笔记
  • 线程同步与互斥核心要点整理
  • 即时设计笔记
  • C++搞定周岁.虚岁计算
  • 【网络】HTTP报文首部字段
  • 使用 ECharts 在 Vue3 中柱状图的完整配置解析
  • 大数据测试集群环境部署
  • linux 内核 debugfs 使用介绍
  • Python 打包兼容Win7 的Qt 程序
  • 【题解-Acwing】869. 试除法求约数
  • 解决react-native下背景图渲染,统一处理组件BackgroundImage
  • 【Python笔记 05】 if判断、比较运算符与逻辑运算符
  • 《AI大模型应知应会100篇》【精华】第40篇:长文本处理技巧:克服大模型的上下文长度限制
  • 如何防止丝杆支撑座锈蚀?
  • MIT6.S081-lab7
  • 第12讲:组合多图(Patchwork)艺术
  • C++复习补充 IO
  • Nginx核心功能与LNMP部署
  • C语言Makefile编写与使用指南
  • 小米喷墨打印机Mi All-in-One Inkjet Printer电脑通过管理打印设备扫描文件方法完整记录
  • 「国产嵌入式仿真平台:高精度虚实融合如何终结Proteus时代?」——从教学实验到低空经济,揭秘新一代AI赋能的产业级教学工具
  • 使用O_DIRECT + 批量写数据到磁盘对丢包率的优化
  • Hanko:身份验证和用户管理解决方案,Clerk Auth0 的开源替代
  • [密码学实战]SDF之对称运算类函数(四)
  • 【缓冲区分析】叠加分析-要素叠加
  • Plesk 下的 IP 地址管理
  • MicroBlaze软核的开发使用
  • 分步详解:凤凰6000模拟器接入Unity Input System‌(
  • docker排查OOM Killer