Pip
baidupcsapi 的安装用到了 pip 命令行。
运行
$ sudo easy_install pip
日志如下
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 9.0.1
Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
Processing pip-9.0.1.tar.gz
Writing /tmp/easy_install-AtksdY/pip-9.0.1/setup.cfg
Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-AtksdY/pip-9.0.1/egg-dist-tmp-T9OrMy
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
creating /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Extracting pip-9.0.1-py2.7.egg to /Library/Python/2.7/site-packages
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
baidupcsapi
- Installation
$ sudo pip install baidupcsapi
命令行
houbinbindeMacBook-Pro:~ houbinbin$ sudo pip install baidupcsapi
The directory '/Users/houbinbin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/houbinbin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting baidupcsapi
Downloading baidupcsapi-0.3.8.tar.gz
Collecting requests>=1.1.0 (from baidupcsapi)
Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
100% |████████████████████████████████| 92kB 1.5MB/s
Collecting requests_toolbelt>=0.1.2 (from baidupcsapi)
Downloading requests_toolbelt-0.8.0-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 3.0MB/s
Collecting rsa>=3.1.4 (from baidupcsapi)
Downloading rsa-3.4.2-py2.py3-none-any.whl (46kB)
100% |████████████████████████████████| 51kB 3.9MB/s
Collecting idna<2.7,>=2.5 (from requests>=1.1.0->baidupcsapi)
Downloading idna-2.6-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 3.1MB/s
Collecting urllib3<1.23,>=1.21.1 (from requests>=1.1.0->baidupcsapi)
Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 2.3MB/s
Collecting certifi>=2017.4.17 (from requests>=1.1.0->baidupcsapi)
Downloading certifi-2017.7.27.1-py2.py3-none-any.whl (349kB)
100% |████████████████████████████████| 358kB 1.6MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests>=1.1.0->baidupcsapi)
Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 2.9MB/s
Collecting pyasn1>=0.1.3 (from rsa>=3.1.4->baidupcsapi)
Downloading pyasn1-0.3.3-py2.py3-none-any.whl (63kB)
100% |████████████████████████████████| 71kB 3.8MB/s
Installing collected packages: idna, urllib3, certifi, chardet, requests, requests-toolbelt, pyasn1, rsa, baidupcsapi
Running setup.py install for baidupcsapi ... done
Successfully installed baidupcsapi-0.3.8 certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 pyasn1-0.3.3 requests-2.18.4 requests-toolbelt-0.8.0 rsa-3.4.2 urllib3-1.22
- run
houbinbindeMacBook-Pro:~ houbinbin$ python
Python 2.7.10 (default, Feb 6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from baidupcsapi import PCS
>>> pcs = PCS('username','password')
https://passport.baidu.com/cgi-bin/genimage?jxG7e07c1d4e066c16f020b14714301af7fc619430754057e2f
open url aboved with your web browser, then input verify code > 十个特辑
>>> print pcs.list_files('/').content
{"errno":0,"guid_info":"","list":[{"category":6,"unlist":0,"fs_id":124323384624666,"oper_id":0,"server_ctime":1495210847,"isdir":1,"local_mtime":1495210847,"size":0,"server_filename":"\u6211\u7684\u8d44\u6e90","share":0,"path":"\/\u6211\u7684\u8d44\u6e90","local_ctime":1495210847,"server_mtime":1495210847},{"category":6,"unlist":0,"fs_id":338767527673459,"oper_id":3344673711,"server_ctime":1504061716,"isdir":1,"local_mtime":1504061716,"size":0,"server_filename":"music","share":0,"path":"\/music","local_ctime":1504061716,"server_mtime":1504061716},{"category":6,"unlist":0,"fs_id":132376286846029,"oper_id":3344673711,"server_ctime":1504228816,"isdir":1,"local_mtime":1504228816,"size":0,"server_filename":"backup","share":0,"path":"\/backup","local_ctime":1504228816,"server_mtime":1504228816},{"category":6,"unlist":0,"fs_id":911687856236880,"oper_id":0,"server_ctime":1504070498,"isdir":1,"local_mtime":1504070498,"size":0,"server_filename":"apps","share":0,"path":"\/apps","local_ctime":1504070498,"server_mtime":1504070498},{"server_mtime":1504430870,"category":3,"unlist":0,"fs_id":285222447209323,"oper_id":3344673711,"server_ctime":1504430870,"isdir":0,"local_mtime":1504430870,"size":3738458,"share":0,"md5":"8051d5543ce5b0597ac01e1228ed1c8a","path":"\/\u5c4f\u5e55\u5feb\u7167 2017-09-03 \u4e0b\u53483.46.46 1.png","local_ctime":1504430870,"server_filename":"\u5c4f\u5e55\u5feb\u7167 2017-09-03 \u4e0b\u53483.46.46 1.png"}],"request_id":5700560363339757545,"guid":0}
这里的操作很多需要使用人工校验验证码,很痛苦。
Python
更新 mac python 版本。(默认为 v2.7)
直接下载安装https://www.python.org/ftp/python/3.5.0/python-3.5.0-macosx10.6.pkg。
houbinbindeMacBook-Pro:~ houbinbin$ python3
Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
路径测试
houbinbindeMacBook-Pro:~ houbinbin$ which python
/usr/bin/python
houbinbindeMacBook-Pro:~ houbinbin$ which python3
/usr/local/bin/python3