How to download a file using python in a 'smarter' way?

前端 未结 5 1596
盖世英雄少女心
盖世英雄少女心 2020-11-27 10:04

I need to download several files via http in Python.

The most obvious way to do it is just using urllib2:

import urllib2
u = urllib2.urlopen(\'http:/         


        
5条回答
  •  时光取名叫无心
    2020-11-27 10:34

    Using wget:

    custom_file_name = "/custom/path/custom_name.ext"
    wget.download(url, custom_file_name)
    

    Using urlretrieve:

    urllib.urlretrieve(url, custom_file_name)
    

    urlretrieve also creates the directory structure if not exists.

提交回复
热议问题