urllib2 file name

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

    Do you mean urllib2.urlopen? There is no function called openfile in the urllib2 module.

    Anyway, use the urllib2.urlparse functions:

    >>> from urllib2 import urlparse
    >>> print urlparse.urlsplit('http://example.com/somefile.zip')
    ('http', 'example.com', '/somefile.zip', '', '')
    

    Voila.

提交回复
热议问题