如何用Python通过Terabox API下载Terabox文件?

0 投票
2 回答
429 浏览
提问于 2025-04-14 17:58

我想通过 terabox 的 API 下载文件。我该怎么做呢?我试了很多资料,但都没有成功。我在一个 GitHub 的项目里找到了这个,但也不管用。

from urllib.parse import urlparse, parse_qs
import requests
import re


def extract_domain_and_surl(url):
    

    return urlparse(url).netloc, urlparse(url).path[3:]


def parseCookieFile(cookiefile):
    
    cookies = {}
    with open(cookiefile, 'r') as fp:
        for line in fp:
            if not line.startswith('#'):
                line_fields = line.strip().split('\t')
                # Make sure the line has at least 7 fields, as per Netscape format
                if len(line_fields) >= 7:
                    # Extract the cookie name and value
                    cookie_name = line_fields[5]
                    cookie_value = line_fields[6]
                    cookies[cookie_name] = cookie_value
    return cookies


def download(url: str) -> str:
    

    axios = requests.Session()

    # Load cookies from 'cookies.txt'
    cookies = parseCookieFile('cookies.txt')
    axios.cookies.update(cookies)

    response = axios.get(url)
    domain, key = extract_domain_and_surl(response.url)

    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'en-US,en;q=0.5',
        'Accept-Encoding': 'gzip, deflate, br',
        'Referer': f'https://{domain}/sharing/link?surl={key}',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'
    }

    response = axios.get(
        f'https://www.terabox.com/share/list?app_id=250528&shorturl={key}&root=1', headers=headers)
    
    print(response.text)

    try:
        result = response.json()['list'][0]['dlink']
    except KeyError:
        print("Failed to get download link")
    else:
        return result


# Example usage
dlink = download('https://teraboxapp.com/s/1RCBLl4RBXh446ZKoHgHZJt_Q')
print(dlink)

我需要用任何编程语言写的代码来下载 terabox 上的文件。

2 个回答

0

我没有在上面的代码中找到任何解决方案。
不过,我发现了一些小窍门,可以通过API请求从Terabox下载文件。我简单地从很多网站收集了第三方的API(可以在谷歌上搜索)。通过这些API,我成功地从Terabox下载了文件。

0

你可以使用 https://teradownloader.com 这个网站来下载 terabox 的文件。我自己也在用这个网站,它是唯一一个支持文件夹下载的网站。如果你想做一个类似的网站,还有一个快速API可以使用。这个API的链接是 https://rapidapi.com/sampatsharma865/api/terabox-downloader-direct-download-link-generator

撰写回答