urllib2 file name

前端 未结 14 1827
感动是毒
感动是毒 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:13

    Using urlsplit is the safest option:

    url = 'http://example.com/somefile.zip'
    urlparse.urlsplit(url).path.split('/')[-1]
    

提交回复
热议问题