生活随笔
收集整理的這篇文章主要介紹了
python登录百度网盘
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
閱讀文章之前,有一些東西需要給大家闡述:
以下是用Python實現登錄百度云盤的代碼:```python
import requests# 登錄信息
username = input('請輸入百度賬號:')
password = input('請輸入密碼:')# 創建會話
session = requests.session()# 獲取token
response = session.get('https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true')
token = response.json()['data']['token']# 發送驗證碼登錄請求
response = session.get('https://passport.baidu.com/v2/api/?logincheck&token={}&tpl=mn&apiver=v3&tt=1586463173434&username={}'.format(token, username))
code_string = response.json()['data']['codeString']
print('驗證碼鏈接:https://passport.baidu.com/cgi-bin/genimage?{}'.format(code_string))# 登錄請求
code_input = input('請輸入驗證碼:')
response = session.post('https://passport.baidu.com/v2/api/?login', data={'staticpage': 'https://www.baidu.com/', # 固定值'charset': 'UTF-8', # 固定值'token': token,'tpl': 'mn','subpro': '', # 固定值'apiver': 'v3','tt': '1586463173434','codestring': code_string,'safeflg': '0','u': 'https://www.baidu.com/', # 固定值'isPhone': '','quick_user': '0','logintype': 'basicLogin','logLoginType': 'pc_loginBasic','loginmerge': 'true','username': username,'password': password,'mem_pass': 'on','rsakey': '','crypttype': '','ppui_logintime': 27691,'verifycode': code_input, # 驗證碼輸入框'callback': 'parent.bd__pcbs__ra48vi' # 固定值
})# 驗證是否登錄成功
response = session.get('https://pan.baidu.com/disk/home')
if '個人網盤' in response.text:print("登錄成功!")
else:print("登錄失敗!")
```
總結
以上是生活随笔為你收集整理的python登录百度网盘的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。