Python 一鍵獲取百度網(wǎng)盤提取碼的方法

該 GIF 圖來(lái)自于官網(wǎng),文末有給出鏈接。
描述
依托于百度網(wǎng)盤巨大的的云存儲(chǔ)空間,絕大數(shù)人會(huì)習(xí)慣性的將一些資料什么的存儲(chǔ)到上面,但是有的私密鏈接需要提取碼,但是讓每個(gè)想下載私密資源的人記住每一個(gè)提取碼顯然是不現(xiàn)實(shí)的。這個(gè)時(shí)候,云盤萬(wàn)能鑰匙 誕生了,我們通過(guò)安裝相應(yīng)的瀏覽器插件就可以自動(dòng)獲獲取相應(yīng)鏈接的提取碼。我在 Github 上看了一下,有 Web JS 版的, python 版的貌似還沒(méi)有找到,所以我參照了JS 版本和官網(wǎng)的請(qǐng)求接口寫了兩種方式的獲取腳本。
實(shí)現(xiàn)
下述兩種方式的具體實(shí)現(xiàn)就不做代碼解釋了,思路都是一樣,通過(guò)請(qǐng)求接口,拿到數(shù)據(jù),然后返回即可。
v1
"""
Author:hippieZhou
Date:20190608
Description: Get BaiDuYun shared link's Code
"""
import argparse
import re
import requests
import json
import time
VERSION = "VERSION 1.0.0"
def checkUrl(url: str) -> str:
m1 = re.match(
"https?:\/\/pan\.baidu\.com\/s\/1([a-zA-Z0-9_\-]{5,22})", url)
m2 = re.match(
"https?:\/\/pan\.baidu\.com\/share\/init\?surl=([a-zA-Z0-9_\-]{5,22})", url)
if not m1 and not m2:
print("參數(shù)不合法")
return False
else:
return True
def getKey(url: str) -> bool:
if checkUrl(url):
try:
req = requests.get(f"https://node.pnote.net/public/pan?url={url}")
code = req.status_code
if code == 200:
data = dict(json.loads(req.text))
status = data.get("status", False)
if status:
return data.get("access_code", "未能查詢到該鏈接的提取碼,可能原因是:該鏈接不需要提取碼或已過(guò)期")
else:
return data.get("messages", "為能查詢到提取碼")
elif code == 404:
return "不存在該鏈接的記錄"
except Exception as e:
return f"請(qǐng)求服務(wù)器失敗,錯(cuò)誤代碼:[code]"
def get_parser():
parser = argparse.ArgumentParser()
parser.description = "百度網(wǎng)盤提取碼一鍵獲取器"
parser.add_argument('urls', metavar="urls", type=str, nargs="*",
help='設(shè)置要獲取提取碼的鏈接(多個(gè)鏈接請(qǐng)用空格分隔)')
parser.add_argument('-v', '--version', action='store_true',
help='版本號(hào)')
return parser
def command_line_runner():
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(VERSION)
return
s_time = time.time()
if len(args['urls']) > 1:
for item in args["urls"][1:]:
print(f"{item}:\r\n\t{getKey(item)}")
e_time = time.time()
print(f"\n\n操作完畢,總耗時(shí):{e_time-s_time} 秒")
def main():
command_line_runner()
if __name__ == "__main__":
main()
運(yùn)行效果如下圖所示:

v2
"""
Author:hippieZhou
Date:20190608
Description: Get BaiDuYun shared link's Code
"""
import argparse
import time
import re
import requests
from datetime import datetime
import json
accessKey = "4fxNbkKKJX2pAm3b8AEu2zT5d2MbqGbD"
clientVersion = "web-client"
def getPid(url: str) -> str:
matches = re.match(
"https?:\/\/pan\.baidu\.com\/s\/1([a-zA-Z0-9_\-]{5,22})", url)
return matches[1] if matches else None
def getUuid(pid: str) -> str:
return f"BDY-{pid}"
def getKey(url: str) -> str:
pid = getPid(url)
uuid = getUuid(pid)
headers = {
"type": "GET",
"data": '',
"dataType": "json"
}
url = f"http://ypsuperkey.meek.com.cn/api/items/{uuid}?access_key={accessKey}&client_version={clientVersion}&{datetime.utcnow()}"
try:
req = requests.get(url, headers=headers)
code = req.status_code
if code == 200:
data = json.loads(req.text)
accessCode = data.get("access_code", None)
return "沒(méi)找到提取密碼,o(╥﹏╥)o" if (accessCode == "undefined" or accessCode == None or accessCode == "") else accessCode
elif code == 400:
return " 服務(wù)器不理解請(qǐng)求的語(yǔ)法"
elif code == 404:
return "不存在該鏈接的記錄"
else:
return f"請(qǐng)求服務(wù)器失敗,錯(cuò)誤代碼:[code]"
except Exception as e:
return e
def get_parser():
parser = argparse.ArgumentParser()
parser.description = "百度網(wǎng)盤提取碼一鍵獲取器"
parser.add_argument('urls', metavar="urls", type=str, nargs="*",
help='設(shè)置要獲取提取碼的鏈接(多個(gè)鏈接請(qǐng)用空格分隔)')
parser.add_argument('-v', '--version', action='store_true',
help='版本號(hào)')
return parser
def command_line_runner():
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(VERSION)
return
s_time = time.time()
if len(args['urls']) > 1:
for item in args["urls"][1:]:
print(f"{item}:\r\n\t{getKey(item)}")
e_time = time.time()
print(f"\n\n操作完畢,總耗時(shí):{e_time-s_time} 秒")
def main():
command_line_runner()
if __name__ == "__main__":
main()
運(yùn)行效果如下圖所示:

總結(jié)
v1 版本和 v2 版本是通過(guò)請(qǐng)求不同的接口方式來(lái)實(shí)現(xiàn)的, v2 接口的數(shù)據(jù)要相對(duì)更準(zhǔn)確一些。具體可查閱具體的代碼實(shí)現(xiàn)。
如果你覺(jué)得上述代碼不錯(cuò)的話,歡迎訪問(wèn)對(duì)應(yīng)的倉(cāng)庫(kù)地址: baidupankey 進(jìn)行 star 、fork 和 follow。
相關(guān)參考
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 快速一鍵生成Python爬蟲請(qǐng)求頭
- 使用Python制作一個(gè)數(shù)據(jù)預(yù)處理小工具(多種操作一鍵完成)
- 如何打包Python Web項(xiàng)目實(shí)現(xiàn)免安裝一鍵啟動(dòng)的方法
- 利用Python代碼實(shí)現(xiàn)一鍵摳背景功能
- Ubuntu18.04 一鍵升級(jí)Python所有第三方包 及安裝python包的方法
- Python一鍵安裝全部依賴包的方法
- Python一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資源
- Python 一鍵制作微信好友圖片墻的方法
- Python字典循環(huán)添加一鍵多值的用法實(shí)例
- Python趣味爬蟲之用Python實(shí)現(xiàn)智慧校園一鍵評(píng)教
相關(guān)文章
Python使用Pandas庫(kù)實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的讀寫
這篇文章主要介紹了Python使用Pandas庫(kù)實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的讀寫 ,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Pycharm如何對(duì)python文件進(jìn)行打包
這篇文章主要介紹了Pycharm如何對(duì)python文件進(jìn)行打包,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
python中的print()函數(shù)end=' '的使用及說(shuō)明
這篇文章主要介紹了python中的print()函數(shù)end=' '的使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02
keras 解決加載lstm+crf模型出錯(cuò)的問(wèn)題
這篇文章主要介紹了keras 解決加載lstm+crf模型出錯(cuò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06
讓你分分鐘學(xué)會(huì)python條件語(yǔ)句
學(xué)好Python和條件語(yǔ)句,將方便有效提高工作效率,這篇文章主要給大家介紹了關(guān)于python條件語(yǔ)句的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-08-08
python3實(shí)現(xiàn)二叉樹的遍歷與遞歸算法解析(小結(jié))
這篇文章主要介紹了python3實(shí)現(xiàn)二叉樹的遍歷與遞歸算法解析(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
python cv2在驗(yàn)證碼識(shí)別中應(yīng)用實(shí)例解析
這篇文章主要介紹了python cv2在驗(yàn)證碼識(shí)別中應(yīng)用實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12

