Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中从url保存.doc文件?_Python_Download_Save - Fatal编程技术网

如何在python中从url保存.doc文件?

如何在python中从url保存.doc文件?,python,download,save,Python,Download,Save,我正在尝试找出如何从internet下载/保存.doc文件到我计算机上的某个位置 我熟悉urllib2模块和.read(),但我还不知道如何将格式化的.doc文件保存到计算机上的某个位置。这可能吗?使用库,您可以这样做: r = requests.get(url, stream=True) if r.status_code == 200: with open('document.doc', 'wb') as f: for chunk in r.iter_content()

我正在尝试找出如何从internet下载/保存.doc文件到我计算机上的某个位置

我熟悉urllib2模块和.read(),但我还不知道如何将格式化的.doc文件保存到计算机上的某个位置。这可能吗?

使用库,您可以这样做:

r = requests.get(url, stream=True)
if r.status_code == 200:
    with open('document.doc', 'wb') as f:
        for chunk in r.iter_content():
            f.write(chunk)
    f.close()