urllib2 file name

前端 未结 14 1828
感动是毒
感动是毒 2020-12-01 03:27

If I open a file using urllib2, like so:

remotefile = urllib2.urlopen(\'http://example.com/somefile.zip\')

Is there an easy way to get the

14条回答
  •  执念已碎
    2020-12-01 04:04

    I guess it depends what you mean by parsing. There is no way to get the filename without parsing the URL, i.e. the remote server doesn't give you a filename. However, you don't have to do much yourself, there's the urlparse module:

    In [9]: urlparse.urlparse('http://example.com/somefile.zip')
    Out[9]: ('http', 'example.com', '/somefile.zip', '', '', '')
    

提交回复
热议问题