The Wayback Machine - https://web.archive.org/web/20200621191342/https://github.com/notechats/notedrive
Skip to content
基于PCS的百度网盘的Python-API
Python Shell
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__pycache__
example
notedrive
script
README.md
__init__.py
setup.py

README.md

说明

百度云盘的python-api,官方API

使用场景

数据产出后直接上传备份
1.网上爬取的数据
2.模型训练的结果
3.大一点的数据集

目录

方法 描述
安装 安装方式
list 查看该目录下有哪些文件
meta 可以查看某个文件的具体信息
upload 上传单个文件
download 下载单个文件
upload_dir 上传文件夹
download_dir 下载文件夹

安装

pip install notedrive

或者直接从GitHub安装

pip install git+https://github.com/notechats/notedrive.git

使用

第一次使用

获取百度cookies中的BDUSS值,注意保密

from notedrive.baidu.drive import BaiDuDrive
client = BaiDuDrive(bduss="XXXXXXXXXXXXXXXXXXXXXXXX",save=True)

第一次使用后,会将BDUSS存入'~/.secret/.bduss'(save=True时)

如果允许保存到本地,则下次调用不用传入dbuss,即

from notedrive.baidu.drive import BaiDuDrive
client = BaiDuDrive()

list 查看

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
for path in client.list("/drive/example/api"):
    print(path['server_filename'])

meta 查看

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
print(client.meta("/drive/example/api/test.txt"))

upload 上传单个文件

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
client.upload('test.txt', '/drive/example/api/test.txt', overwrite=False)

download 下载单个文件

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
client.download( '/drive/example/api/test.txt','test2.txt', overwrite=False)

upload_dir 上传文件夹

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
client.upload_dir('logs', '/drive/example/api/')

download_dir 下载文件夹

from notedrive.baidu.drive import BaiDuDrive

client = BaiDuDrive()
client.download_dir('/drive/example/api/', 'logs')

参考

baidupcsapi

baidu-pcs-python-sdk

You can’t perform that action at this time.