How do I download a file over HTTP using Python?

前端 未结 25 3030
感动是毒
感动是毒 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 07:40

    Following are the most commonly used calls for downloading files in python:

    1. urllib.urlretrieve ('url_to_file', file_name)

    2. urllib2.urlopen('url_to_file')

    3. requests.get(url)

    4. wget.download('url', file_name)

    Note: urlopen and urlretrieve are found to perform relatively bad with downloading large files (size > 500 MB). requests.get stores the file in-memory until download is complete.

提交回复
热议问题