我从一个网站上抓取了一个视频下载下来,视频没有播放

2024-06-02 05:19:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从“https://www.thewatchcartoononline.tv/bobs-burgers-season-9-episode-5-live-and-let-fly”下载视频并播放。我可以下载为“汉堡.s09e03.mp4“但无法播放!你知道吗

import requests
import bs4
url = 'https://www.thewatchcartoononline.tv/bobs-burgers-season-9-episode-5-live-and-let-fly'
def download_file(url, filename):
    r = requests.get(url, stream=True)
    with open(filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size = 1024):
            if chunk:
                f.write(chunk)
    return (filename)

download_file(url, "bobs.burgers.s09e03.mp4")

我觉得视频应该下载播放。你知道吗


Tags: andhttpsliveurlwwwtvfilenameseason
1条回答
网友
1楼 · 发布于 2024-06-02 05:19:00

在编写脚本下载网页之后,你不能指望有视频。您的代码下载网页并将其存储在.mp4文件中。以下代码表示作业正确。你知道吗

import requests
import json

url = 'https://www.thewatchcartoononline.tv/inc/embed/getvidlink.php?v=cizgi/bobs.burgers.s09e05.mp4&embed=cizgi&hd=1'

def get_url(url):

    page = requests.get(url,headers={'X-Requested-With': 'XMLHttpRequest','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'}).json()
    download_url = page['cdn']+'/getvid?evid='+page['enc']

    return download_url

def download_video(url,filename):
    r= requests.get(url,headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'},stream=True)
    with open(filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size = 1024):
            if chunk:
                f.write(chunk)
    return (filename)

download_video(get_url(url),"bobs.burgers.s09e03.mp4")

相关问题 更多 >