简体   繁体   English

在指定路径中下载带有 python 的文件?

[英]Download files with python in a specifid path?

Hello i want do download a file with python, it works great but how can i save the file in a specifid path?你好,我想用 python 下载一个文件,它工作得很好,但我怎样才能将文件保存在一个特定的路径中? MY CODE:我的代码:

url144 = "https://cdn.discordapp.com/attachments/815696193354203157/817144742693437490/msgbox.vbs"
r = requests.get(url144, allow_redirects=True)
open("msgbox.vbs", "wb").write(r.content)

You are doing it exactly right, there is nothing to be improved in your code, To change the path its saved to, just put it in the first argument to the opne call !您做得完全正确,您的代码没有什么需要改进的地方,要更改其保存的路径,只需将其放在opne调用的第一个参数中!

like Copperfield said就像科波菲尔说的

your codes must be like this:您的代码必须是这样的:

url144 = "https://cdn.discordapp.com/attachments/815696193354203157/817144742693437490/msgbox.vbs"
r = requests.get(url144, allow_redirects=True)

open("/path/where/you/want/your/file/msgbox.vbs", "wb").write(r.content)

You just need to do it using "with" which will close file once operation is completed您只需要使用“with”来完成操作,一旦操作完成,它将关闭文件

with open("msgbox.vbs", "wb") as f:
    f.write(r.content)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM