前言
批量转存百度网盘分享资源Python脚本,解封双手,无需一个个链接的点击保存。
通过解析百度网盘保存链接,只需要要保存的网盘资源链接,用户的Cookie和需要保存到的路径,文件名只是便于控制台查看结果,并无实际作用。
上传模式分为单个文件和多个文件(txt文件),批量保存可选择多文件保存。
python脚本代码
# -*- encoding: utf-8 -*- ''' [url=home.php?mod=space&uid=267492]@file[/url] : BaiduPan.py [url=home.php?mod=space&uid=238618]@Time[/url] : 2022/08/24 11:54:57 [url=home.php?mod=space&uid=686208]@AuThor[/url] : Arctic [url=home.php?mod=space&uid=1248337]@version[/url] : 1.0 @Contact : [email]784060033@qq.com[/email] [url=home.php?mod=space&uid=1781681]@desc[/url] : ''' import math import random import re import requests import base64 from urllib.parse import unquote class BaiduPan: def __init__(self, cookie) -> None: self.headers = { 'Host': 'pan.baidu.com', 'Cookie': cookie, 'User-Agent': 'Mozilla/5.0' } def get_info(self, url): res = requests.get(url, headers=self.headers) share_uk = re.findall(r'share_uk:"(d+)"', res.text)[0] shareid = re.findall(r'shareid:"(d+)"', res.text)[0] app_id = re.findall(r'app_id":"(d+)"', res.text)[0] fs_id = re.findall(r'fs_id":(d+),', res.text)[0] bdstoken = re.findall(r"bdstoken:'(w+)'", res.text)[0] return (share_uk, shareid, app_id, fs_id, bdstoken) def getDpLogId(self, uk=None): def getRandomInt(num): return str(math.floor((random.random() * 9 + 1) * math.pow(10, num - 1))) def validateUk(uk): return len(uk + '') == 10 def prefixInteger(num, length): return ''.join(['0' for _ in range(length - len(num))]) + num def getCountId(countid=30): if countid < 9999: countid += 1 else: countid = 0 return prefixInteger(str(countid), 4) client = '' userid = '00' + getRandomInt(8) sessionid = getRandomInt(6) if uk and validateUk(uk): userid = uk return client + sessionid + userid + getCountId() def upload(self, uri, path='/我的资源'): url = 'https://pan.baidu.com/share/transfer' headers = self.headers.copy() headers['Referer'] = uri share_uk, shareid, app_id, fs_id, bdstoken = self.get_info(uri) sekey = unquote(re.findall(r'BDCLND=(.+?);', headers['Cookie'])[0]) logid = base64.b64encode(re.findall(r'BAIDUID=(.+?);', headers['Cookie'])[0].encode()).decode() dplogid = self.getDpLogId() params = { 'shareid': shareid, 'from': share_uk, 'sekey': sekey, 'channel': 'chunlei', 'web': '1', 'app_id': app_id, 'bdstoken': bdstoken, 'logid': logid, 'clienttype': '0', 'dp-logid': dplogid, } data = { 'fsidlist': f'[{fs_id}]', 'path': path } resp = requests.post(url, headers=headers, params=params, data=data).json() # pprint.pp(resp) if resp['errno'] == 0: return '保存网盘成功。' elif resp['errno'] == 4: return '已经保存过了。' elif resp['errno'] == 2: return '保存时出现未知错误。' else: return resp['show_msg'] # 单个文件保存 def sing_upload(name, url, cookie, path='/我的资源'): pan = BaiduPan(cookie) print(name + pan.upload(url, path)) # 多个文件保存 def txt_upload(file, cookie, path='/我的资源'): with open(file, 'r', encoding='utf8') as f: datas = [data.strip().split() for data in f.readlines() if data.strip()] pan = BaiduPan(cookie) for data in datas: name, url = data print(name + pan.upload(url, path)) if __name__ == '__main__': print('***百度网盘批量保存***') print('n请将百度账号cookie复制到cookie.txt文件中') with open('cookie.txt', 'r', encoding='utf8') as f: cookie = f.read() mode = input('n1. 单个文件保存n2. 多个文件保存(txt文件)n选择模式:') if mode == '1': name = input('输入文件名称:') url = input('输入网盘链接:') path = input('输入保存路径(不输入默认保存至 /我的资源):') if not path: path = '/我的资源' sing_upload(name, url, cookie, path) elif mode == '2': file = input('输入txt文件路径:') path = input('输入保存路径(不输入默认保存至 /我的资源):') if not path: path = '/我的资源' txt_upload(file, cookie, path)
完整示例脚本下载:https://pan.baidu.com/s/19fEGBA4quuT2R7CCuULY5w?pwd=84up
百度网盘
2020-12-11 749百度网盘是目前用户最多的网盘,本站全部资源也均在百度网盘,为了方便本站用户使用百度网盘,特意收藏收藏整理了关于百度网盘下载专题,包含各种百度网盘破解版,百...
- ODE(窝的)百度网盘不限速解析下载工具V0.9.8 [2024-08-30]
- 最新版ODE(窝的)百度网盘不限速解析下载工具 [2024-06-22]
- Gopeed百度网盘加速下载扩展插件 [2024-06-21]
- K胖解析-百度云高速解析油猴脚本 [2024-04-24]
- K胖解析-最新百度网盘在线解析工具 [2024-04-24]