使用请求获取自动下载链接

Grab auto Download Links Using requests

我正在尝试使用 Bs4

Yourupload 抓取自动启动的直接下载 Link

直接下载Link每次自动生成, 直接下载Link也是5秒后自动开始, 我想直接下载 Link 并将其存储在 "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)

好吧,实际上该网站是 运行 一个 JavaScript 代码来处理重定向到 final-destination url 到 stream 下载 [= =15=]验证。

现在我们变狼了,挺过来的。

我们将首先发送一个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

Notice that the download link is one time callable as the token is only validated one-time by the back-end.