获取python变量中的wget输出
我可以使用wget下载该文件,并且可以在控制台中看到进度,但是如何将该输出存储到python变量中呢 下面给出了一个示例代码,类似这样的东西我是例外获取python变量中的wget输出,python,wget,openwrt,Python,Wget,Openwrt,我可以使用wget下载该文件,并且可以在控制台中看到进度,但是如何将该输出存储到python变量中呢 下面给出了一个示例代码,类似这样的东西我是例外 output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf') 我不建议使用wget,而是使用urllib: 如果必须使用wget,只需在wget写入输出文件后读取它即可 os.system('wget https://www.tutori
output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf')
我不建议使用wget,而是使用urllib: 如果必须使用wget,只需在wget写入输出文件后读取它即可
os.system('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf -O your_file_path')
print open('your_file_path').read()
通常,您可以通过子进程捕获程序的标准输出
import subprocess
output = subprocess.check_output('ping localhost', stderr=subprocess.STDOUT, shell=True)
@Peter Wood可能重复,wget结果与其他操作系统命令不同results@Arun在链接副本上