urllib2 file name

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

    import os,urllib2
    resp = urllib2.urlopen('http://www.example.com/index.html')
    my_url = resp.geturl()
    
    os.path.split(my_url)[1]
    
    # 'index.html'
    

    This is not openfile, but maybe still helps :)

提交回复
热议问题