【问题标题】:Could not download a video from a link using requests无法使用请求从链接下载视频
【发布时间】:2021-02-08 07:25:32
【问题描述】:

我创建了一个脚本来从this link 下载视频。到目前为止我尝试过的方法似乎根本不起作用。

import requests

video_link = 'https://resources.newscdn.com.au//cs//video//vjs//stable//build//index.html?id=5348771529001-5977442689001&=domain=del'

with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
    with open("delicious.mp4","wb") as f:
        f.write(s.get(video_link,stream=True).content)

如何从上面的链接下载视频?

【问题讨论】:

    标签: python python-3.x web-scraping python-requests


    【解决方案1】:
    import requests
    
    
    headers = {'User-Agent': 'Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;AvantBrowser)'}
    
    with open("delicious.ts", 'wb') as f:
        for i in range(6):
            url = 'https://nws-bolt-amd-prod.akamaized.net/media/v1/hls/v4/clear/5348771529001/817d6bbd-f04a-4be7-8df1-7840daea9951/7bbe9b18-1754-4cfc-b110-ee9a08d94589/5x/segment{}.ts?akamai_token=exp=1615091351~acl=/media/v1/hls/v4/clear/5348771529001/817d6bbd-f04a-4be7-8df1-7840daea9951/7bbe9b18-1754-4cfc-b110-ee9a08d94589/*~hmac=4882307c77be752bf8972da100c9ee65dd091dc6a225eea9727dd55e92751300'.format(
                i)
            response = requests.get(url, headers=headers, stream=True)
            f.write(response.content)
    
    

    【讨论】:

    • Johnny-san,很慢,有什么办法可以改善吗?
    • @ThuấnĐàoMinh 多进程,我在尝试。
    • Johnny-san,我不是发布上述帖子的人。我使用你的源代码尝试下载一个 mp4 文件,我发现它很慢。
    • 它完美地做到了@Johnny。您是如何找到在脚本中使用的 url 的?谢谢。
    • 更新............解析播放过程找到视频信息的主文件
    猜你喜欢
    • 2022-06-30
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2020-12-15
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多