How do I download a file over HTTP using Python?

前端 未结 25 3497
感动是毒
感动是毒 2020-11-21 07:17

I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I\'ve added to iTunes.

The te

25条回答
  •  深忆病人
    2020-11-21 08:02

    You can get the progress feedback with urlretrieve as well:

    def report(blocknr, blocksize, size):
        current = blocknr*blocksize
        sys.stdout.write("\r{0:.2f}%".format(100.0*current/size))
    
    def downloadFile(url):
        print "\n",url
        fname = url.split('/')[-1]
        print fname
        urllib.urlretrieve(url, fname, report)
    

提交回复
热议问题