qiyeboy / SpiderBook

<<python爬虫开发与项目实战>>书籍配套源码和说明
MIT License
984 stars 520 forks source link

Pyhon爬虫开发项目与实践当中的bug #117

Open RichardlauCx opened 5 years ago

RichardlauCx commented 5 years ago

在本书P14页当中的复制文件shutil.copy("oldfile", "newfile")进行第二个方案,newfile可以是目标目录时无法成功进行,不知何解 代码如下:shutil.copy(r".\Richard_exercise", r"F:\Computer\Compute;r_Python\Exercise") 报错如下:Traceback (most recent call last): File "E:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('F:/Computer/Computer_Python/File_operation_exercise/File_operation_exercise.py', wdir='F:/Computer/Computer_Python/File_operation_exercise') File "E:\PyCharm Community Edition 2018.2.4\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "E:\PyCharm Community Edition 2018.2.4\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "F:/Computer/Computer_Python/File_operation_exercise/File_operation_exercise.py", line 58, in shutil.copy(r".\Richard_exercise", r"F:\Computer\Compute;r_Python\Exercise") File "E:\Anaconda\lib\shutil.py", line 241, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "E:\Anaconda\lib\shutil.py", line 120, in copyfile with open(src, 'rb') as fsrc: PermissionError: [Errno 13] Permission denied: '.\Richard_exercise'

RichardlauCx commented 5 years ago

找到问题原因啦,是因为shutil.copy()中的newfile 强调的一直都是文件,所以改为shutil.copy(r".\Richard_exercise.txt", r"F:\Computer\Computer_Python\Exercise")之后就可以了,希望大家不要犯这样的语法错误,领悟透彻了再下手