【问题标题】:Grab auto Download Links Using requests使用请求获取自动下载链接
【发布时间】:2020-03-09 13:40:22
【问题描述】:

我正在尝试使用 Bs4 从Yourupload 获取自动启动的直接下载链接

每次都会自动生成直接下载链接, 直接下载链接也会在 5 秒后自动启动, 我想获取直接下载链接并将其存储在“Link.txt”文件中

import requests
import bs4

req = requests.get('https://www.yourupload.com/download?file=2573285', stream = True)

req = bs4.BeautifulSoup(req.text,'lxml')

print(req)

【问题讨论】:

  • 请提供一个最小的代码示例。
  • @ManaliKagathara OP 已经提供了一个最小的示例。

标签: python web-scraping beautifulsoup download python-requests


【解决方案1】:

嗯,实际上该站点正在运行 JavaScript 代码来处理重定向到 final-destination url 到 stream 的下载,只需 token 验证。

现在我们将成为更多的狼并度过难关。

我们将发送GET request 首先通过requests.Session() 维护session 以维护session 对象,然后再次发送GET 请求以下载Video :)。

这意味着你目前拥有最终的url,你可以做任何事情,现在或以后下载它。

import requests
from bs4 import BeautifulSoup


def Main():
    main = "https://www.yourupload.com/download?file=2573285"
    with requests.Session() as req:
        r = req.get(main)
        soup = BeautifulSoup(r.text, 'html.parser')
        token = soup.findAll("script")[2].text.split("'")[1][-4:]
        headers = {
            'Referer': main
        }
        r = req.get(
            f"https://www.yourupload.com/download?file=2573285&sendFile=true&token={token}", stream=True, headers=headers)
        print(f"Downloading From {r.url}")
        name = r.headers.get("Content-Disposition").split('"')[1]
        with open(name, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024*1024):
                if chunk:
                    f.write(chunk)
            print(f"File {name} Saved.")


Main()

输出:

Downloading From https://s205.vidcache.net:8166/play/a202003090La0xSot1Kl/okanime-2107-HD-19_99?&attach=okanime-2107-HD-19_99.mp4
File okanime-2107-HD-19_99.mp4 Saved.

按大小确认:如您所见250M

请注意,下载链接是一次性可调用的,因为令牌仅由后端验证一次。

【讨论】:

    猜你喜欢
    • 2018-11-24
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多