username = "your baidu acount" #配置你的百度账号 password = "your baidu password" #配置你的百度密码 |
问题:
在github上tigerstudent提出了两个问题:
1.文件spiderMan.py中获取当前脚本所在的目录 root = os.path.dirname(__file__)+"/" 获取到的目录为空,建议应该用os.getcwd()。
这里我实际想要的是当前脚本所在的绝对路径,正确的脚本应该是这样的:os.path.abspath(os.path.dirname(__file__))+"/"
那么为什么os.path.dirname(__file__)和os.getcwd()为什么都不行呢?os.path.dirname(__file__)是当前脚本相对于脚本的执行目录的相对路径,而os.getcwd()是脚本实际执行的目录。新建test.py文件,代码如下:
import os print("os.path.dirname(__file__):"+os.path.dirname(__file__)) print("os.getcwd():"+os.getcwd()) |
os.path.dirname(__file__):/home/fengzheng/vimPython/BaiduMusicSpider-master os.getcwd(): |
os.path.dirname(__file__):BaiduMusicSpider-master os.getcwd():/home/fengzheng/vimPython |