Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remotefile = urllib2.urlopen('http://example.com/somefile.zip')
- filename = url.split('/')[-1].split('#')[0].split('?')[0]
- >>> urlparse.urlsplit('http://example.com/somefile.zip')
- ('http', 'example.com', '/somefile.zip', '', '')
- >>> urlparse.urlsplit('http://example.com/somedir/somefile.zip')
- ('http', 'example.com', '/somedir/somefile.zip', '', '')
- >>> 'http://example.com/somefile.zip'.split('/')[-1]
- 'somefile.zip'
- >>> 'http://example.com/somedir/somefile.zip'.split('/')[-1]
- 'somefile.zip'
- >>> from urllib2 import urlparse
- >>> print urlparse.urlsplit('http://example.com/somefile.zip')
- ('http', 'example.com', '/somefile.zip', '', '')
- In [9]: urlparse.urlparse('http://example.com/somefile.zip')
- Out[9]: ('http', 'example.com', '/somefile.zip', '', '', '')
- [user@host]$ python
- Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import os
- >>> os.path.basename("http://example.com/somefile.zip")
- 'somefile.zip'
- >>> os.path.basename("http://example.com/somedir/somefile.zip")
- 'somefile.zip'
- >>> os.path.basename("http://example.com/somedir/somefile.zip?foo=bar")
- 'somefile.zip?foo=bar'
- url = 'http://example.com/somefile.zip'
Add Comment
Please, Sign In to add comment