【问题标题】:Download videos from a list of urls (python3)从 url 列表下载视频 (python)
【发布时间】:2020-04-26 16:10:55
【问题描述】:

我有一个网址列表(示例网址),每个网址都包含一个视频:

urls = ['https://...live.com/archive/player?live_id=9368953&artist_id=44176&type=1', 'https://...live.com/archive/player?live_id=9344610&artist_id=44176&type=1']

每个 url 都有以下检查元素:

<div class="row">
  <div class="clearfix">
    <button type="button" class="btn btn-primary" onclick="location.href='https://...video.net/archive/flv/master/0009368953-44176.flv?Policy=a19_&Key-Pair-Id=PN2'"></button>
  </div>
</div>

对于每个 url,我想获取其 location.href 的链接(在本例中为“https://...video.net/archive/flv/master/0009368953-44176.flv?Policy=a19_&Key-Pair-Id=PN2”),并从这些链接下载视频。

提前谢谢你!

【问题讨论】:

    标签: python video web-scraping beautifulsoup web-crawler


    【解决方案1】:
    import requests
    from bs4 import BeautifulSoup
    
    
    lid = [9368953, 9344610]
    aid = [44176, 44176]
    
    
    def main(url):
        with requests.Session() as req:
            for x, y in zip(lid, aid):
                r = req.get(url.format(x, y))
                soup = BeautifulSoup(r.content, 'html.parser')
                target = soup.select_one("button.btn.btn-primary")['onclick'].split("'")[1]
                r = req.get(target)
    
                with open(f"{aid}.flv", 'wb') as f:
                    f.write(r.content)
    
    
    main("https://ope.live.com/archive/player?live_id={}&artist_id={}&type=1")
    

    【讨论】:

    • @VNR 确保复制/粘贴最近的代码更新。
    • @VNR 好吧,我看到您只是在谈论另一个主机,而不是您提到的主机,然后您在谈论一个问题,然后是您要求的问题。无论如何使用verify=False
    • @αԋɱҽԃαмєяιcαη 你有新用户的眼光;)
    • @CONvid19 :D 我应该拿 OSCAR 来耐心思考啊 :P
    猜你喜欢
    • 2015-09-06
    • 1970-01-01
    • 2013-12-04
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 2022-06-30
    相关资源
    最近更新 更多