在 Python 中,如果我使用“wget”使用 os.system(“wget ) 下载文件,它会在屏幕上显示如下:
Resolving...
Connecting to ...
HTTP request sent, awaiting response...
100%[====================================================================================================================================================================>] 19,535,176 8.10M/s in 2.3s
等屏幕上。
我该怎么做才能将此输出保存在某个文件中而不是将其显示在屏幕上?
目前我正在运行命令如下:
theurl = "< file location >"
downloadCmd = "wget "+theurl
os.system(downloadCmd)
The os.system
函数通过 shell 运行命令,因此您也可以将任何 stdio 重定向放在那里。您还应该使用-q
将(安静)标记为 wget。
cmd = "wget -q " + theurl + " >/dev/null 2>&1"
然而,在 python 中,有更好的方法可以做到这一点,例如 libcurl 的 pycurl 包装器,或“stock”urllib2
module.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)