仿云雀网页视频检测下载

环境搭建

ffpemg下载

pip install selenium

pip install BeautifulSoup

pip install ffmpy3

getMovePage.py
python 复制代码
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
edge_path = r"C:\Users\11313\.cache\selenium\msedgedriver\win64\128.0.2739.67\msedgedriver.exe"

class WebBrowser:
    def __init__(self):
        # 无可视化界面
        edge_options = Options()
        edge_options.add_argument('headless')
        #禁用GPU
        edge_options.add_argument('disable-gpu')
        edge_options.add_argument('disable-blink-features=AutomationsControlled')
        # edge_options.add_experimential_option('excludeSwitchs', ['enable-automation'])
        user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0"
        edge_options.add_argument(f'user_agent={user_agent}')
        edge_options.add_argument(f'lang=zh_CN.UTF-8')
        edge_options.add_argument(f'UseWebView2=True')
        #edge_options.add_experimental_option("debuggerAddress", "localhost:64218")
        edge_options.add_argument(f'enable-automation') 
        service = Service(executable_path=edge_path, port=53478, verbose = True)
        self.browser = webdriver.Edge(service=service, options=edge_options)

    def exit(self):
        # 清理,关闭浏览器
        self.browser.quit()

    def getContent(self, url):        
        # 打开目标网页

        # 等待元素加载完成
        self.browser.get(url)
        
        # 获取页面内容
        content = self.browser.page_source
        
        return content

# url="https://www.kankanwu.com/Domestic/sifangguan/player-0-0.html"
# browser = WebBrowser()   
# # 处理页面内容
# print(browser.getContent(url))
# browser.exit()

注: 如果出现python msedgedriver Can not connect to the Service,请手动启动edge_path,将port=53478替换为启动后端口号,再重新启动程序

getM3u8.py
python 复制代码
import requests
from bs4 import BeautifulSoup 
from bs4 import Comment
import getMovePage

# 地址解析
def parselKanKanWuUrl(searchText):
    # search_Obj=search_html.find_all("iframe")
    # print(search_Obj)

    startIndex = searchText.find("https://v8.fentvoss.com")
    if(-1 == startIndex or None == startIndex):
        return []
    endIndex = searchText.find("index.m3u8", startIndex)
    if(-1 == endIndex or None == endIndex):
        return []
    m3u8Url = searchText[startIndex : endIndex + len("index.m3u8")]
    return [m3u8Url]

def getM3u8List(url):
    browser = getMovePage.WebBrowser()   
    # 处理页面内容
    content = browser.getContent(url)

    # search_html=BeautifulSoup(content,"html")
    # print(type(search_html))
    # tags = search_html.getText()
    # print(tags)
    # comments = [tag.string for tag in tags if isinstance(tag.string, Comment)]
    browser.exit()
    # with open("./context.txt", 'w') as file:
    #     file.write('\n'.join(content))
    # print(search_html.contents)
    return parselKanKanWuUrl(content)

# print(getM3u8List("https://www.kankanwu.com/Domestic/sifangguan/player-0-0.html"))
downM3u8.py
python 复制代码
from ffmpy3 import FFmpeg 

def downM3u8(m3u8list):
    FFmpegDir = r"E:\program\ffmpeg\bin\ffmpeg.exe"
    for i,url in enumerate(m3u8list):
        FFmpeg(FFmpegDir, inputs={url: None}, \
        outputs={'第{}集.mp4'.format(i):None}).run()

注: FFmpegDir 需替换为环境搭建时安装位置

saveVideo.py
python 复制代码
import getM3u8
import downM3u8

url = "https://www.kankanwu.com/Domestic/sifangguan/player-0-0.html"

m3u8 = getM3u8.getM3u8List(url)
downM3u8.downM3u8(m3u8)

注:集数切换只需改后缀,如player-0-2.html表示第二集

效果

创作不易,小小的支持一下吧!

相关推荐
诗句藏于尽头24 分钟前
Django模型与数据库表映射的两种方式
数据库·python·django
阿幸软件杂货间27 分钟前
Office转PDF转换器v1.0.py
开发语言·pdf·c#
智数研析社33 分钟前
9120 部 TMDb 高分电影数据集 | 7 列全维度指标 (评分 / 热度 / 剧情)+API 权威源 | 电影趋势分析 / 推荐系统 / NLP 建模用
大数据·人工智能·python·深度学习·数据分析·数据集·数据清洗
扯淡的闲人37 分钟前
多语言编码Agent解决方案(5)-IntelliJ插件实现
开发语言·python
丑小鸭是白天鹅1 小时前
Kotlin协程详细笔记之切线程和挂起函数
开发语言·笔记·kotlin
moxiaoran57531 小时前
Flask学习笔记(一)
后端·python·flask
sali-tec1 小时前
C# 基于halcon的视觉工作流-章34-环状测量
开发语言·图像处理·算法·计算机视觉·c#
java搬砖工-苤-初心不变1 小时前
基于 lua_shared_dict 的本地内存限流实现
开发语言·junit·lua
charlie1145141911 小时前
Kotlin 的 apply / with / run 详解
开发语言·kotlin·程序设计·面对对象
Tiger_shl1 小时前
【层面一】C#语言基础和核心语法-02(反射/委托/事件)
开发语言·c#