V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
turtlekey
V2EX  ›  问与答

求转存百度网盘秒传链接的 Python 脚本

  •  
  •   turtlekey · Mar 9, 2023 · 1690 views
    This topic created in 1147 days ago, the information mentioned may be changed or developed.

    如题,请各位彦祖赐教。 先行感谢🙏🙏🙏。

    Supplement 1  ·  Mar 9, 2023

    谢谢v友的回复和帮助。经过一番搜索,我找到了一个十分契合自己需求的python包(链接:https://github.com/PeterDing/BaiduPCS-Py), 一行命令转存秒传链接:BaiduPCS-Py rp /path/to/save --link 'ced58db7aedce8e1c887754fccccde03#0d02589467f34bdd86d08221e93b2783#33251183#test.gz',十分优雅。

    2 replies    2023-03-09 10:07:20 +08:00
    poyanhu
        1
    poyanhu  
       Mar 9, 2023
    ![转存]( https://imgku.pages.dev/file/25493fc95949692171d3a.png)

    来自 AI 的回答。

    以下是一个简单的 Python 脚本,用于将指定的文件或文件夹转存到百度网盘,并返回转存后的秒传链接:

    import requests
    import json

    def baidu_netdisk_transfer(source_path, dest_path):
    # 获取 access_token
    access_token = 'YOUR_ACCESS_TOKEN'

    # 构造 API 请求 URL
    url = 'https://pan.baidu.com/rest/2.0/xpan/multimedia?access_token=' + access_token

    # 构造 API 请求参数
    headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
    'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
    'method': 'transfer',
    'app_id': '250528',
    'path': source_path,
    'dest': dest_path,
    'ondup': 'newcopy'
    }

    # 发送 API 请求
    response = requests.post(url, headers=headers, data=data)
    result = json.loads(response.content.decode('utf-8'))

    # 获取秒传链接
    if result['errno'] == 0:
    return result['list'][0]['link']
    else:
    return None

    其中,source_path 表示要转存的文件或文件夹的路径,dest_path 表示要将文件或文件夹转存到哪个目录下。access_token 是百度开放平台中创建的开发者账号的 access_token 。

    使用方法:

    source_path = '/path/to/source/file_or_folder'
    dest_path = '/path/to/destination/folder'
    link = baidu_netdisk_transfer(source_path, dest_path)
    print(link)

    这将打印出转存后的秒传链接(如果转存成功的话)。
    op351
        2
    op351  
       Mar 9, 2023
    超过 100 个链接的话建议用 selenium 写个简单的自动化脚本
    不超的话 github 上有个项目直接可以在 windows 上跑的
    名字是 BaiduPanFilesTransfers
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4617 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 10:01 · PVG 18:01 · LAX 03:01 · JFK 06:01
    ♥ Do have faith in what you're doing.