• <bdo id='Uqusn'></bdo><ul id='Uqusn'></ul>
    1. <tfoot id='Uqusn'></tfoot>

      1. <i id='Uqusn'><tr id='Uqusn'><dt id='Uqusn'><q id='Uqusn'><span id='Uqusn'><b id='Uqusn'><form id='Uqusn'><ins id='Uqusn'></ins><ul id='Uqusn'></ul><sub id='Uqusn'></sub></form><legend id='Uqusn'></legend><bdo id='Uqusn'><pre id='Uqusn'><center id='Uqusn'></center></pre></bdo></b><th id='Uqusn'></th></span></q></dt></tr></i><div id='Uqusn'><tfoot id='Uqusn'></tfoot><dl id='Uqusn'><fieldset id='Uqusn'></fieldset></dl></div>
      2. <small id='Uqusn'></small><noframes id='Uqusn'>

        <legend id='Uqusn'><style id='Uqusn'><dir id='Uqusn'><q id='Uqusn'></q></dir></style></legend>

        基本的http文件在python中下载并保存到磁盘?

        Basic http file downloading and saving to disk in python?(基本的http文件在python中下载并保存到磁盘?)

        <small id='3sDYF'></small><noframes id='3sDYF'>

          <bdo id='3sDYF'></bdo><ul id='3sDYF'></ul>
              1. <i id='3sDYF'><tr id='3sDYF'><dt id='3sDYF'><q id='3sDYF'><span id='3sDYF'><b id='3sDYF'><form id='3sDYF'><ins id='3sDYF'></ins><ul id='3sDYF'></ul><sub id='3sDYF'></sub></form><legend id='3sDYF'></legend><bdo id='3sDYF'><pre id='3sDYF'><center id='3sDYF'></center></pre></bdo></b><th id='3sDYF'></th></span></q></dt></tr></i><div id='3sDYF'><tfoot id='3sDYF'></tfoot><dl id='3sDYF'><fieldset id='3sDYF'></fieldset></dl></div>
              2. <tfoot id='3sDYF'></tfoot>
                  <tbody id='3sDYF'></tbody>

                  <legend id='3sDYF'><style id='3sDYF'><dir id='3sDYF'><q id='3sDYF'></q></dir></style></legend>
                • 本文介绍了基本的http文件在python中下载并保存到磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I'm new to Python and I've been going through the Q&A on this site, for an answer to my question. However, I'm a beginner and I find it difficult to understand some of the solutions. I need a very basic solution.

                  Could someone please explain a simple solution to 'Downloading a file through http' and 'Saving it to disk, in Windows', to me?

                  I'm not sure how to use shutil and os modules, either.

                  The file I want to download is under 500 MB and is an .gz archive file.If someone can explain how to extract the archive and utilise the files in it also, that would be great!

                  Here's a partial solution, that I wrote from various answers combined:

                  import requests
                  import os
                  import shutil
                  
                  global dump
                  
                  def download_file():
                      global dump
                      url = "http://randomsite.com/file.gz"
                      file = requests.get(url, stream=True)
                      dump = file.raw
                  
                  def save_file():
                      global dump
                      location = os.path.abspath("D:folderfile.gz")
                      with open("file.gz", 'wb') as location:
                          shutil.copyfileobj(dump, location)
                      del dump
                  

                  Could someone point out errors (beginner level) and explain any easier methods to do this?

                  Thanks!

                  解决方案

                  A clean way to download a file is:

                  import urllib
                  
                  testfile = urllib.URLopener()
                  testfile.retrieve("http://randomsite.com/file.gz", "file.gz")
                  

                  This downloads a file from a website and names it file.gz. This is one of my favorite solutions, from Downloading a picture via urllib and python.

                  This example uses the urllib library, and it will directly retrieve the file form a source.

                  这篇关于基本的http文件在python中下载并保存到磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  <tfoot id='yL8eA'></tfoot>

                    <tbody id='yL8eA'></tbody>

                      <small id='yL8eA'></small><noframes id='yL8eA'>

                            <bdo id='yL8eA'></bdo><ul id='yL8eA'></ul>

                          • <legend id='yL8eA'><style id='yL8eA'><dir id='yL8eA'><q id='yL8eA'></q></dir></style></legend>
                          • <i id='yL8eA'><tr id='yL8eA'><dt id='yL8eA'><q id='yL8eA'><span id='yL8eA'><b id='yL8eA'><form id='yL8eA'><ins id='yL8eA'></ins><ul id='yL8eA'></ul><sub id='yL8eA'></sub></form><legend id='yL8eA'></legend><bdo id='yL8eA'><pre id='yL8eA'><center id='yL8eA'></center></pre></bdo></b><th id='yL8eA'></th></span></q></dt></tr></i><div id='yL8eA'><tfoot id='yL8eA'></tfoot><dl id='yL8eA'><fieldset id='yL8eA'></fieldset></dl></div>