Python split url to find image name and extension

后端 未结 7 1977
逝去的感伤
逝去的感伤 2021-02-04 13:43

I am looking for a way to extract a filename and extension from a particular url using Python

lets say a URL looks as follows

picture_page = \"http://dis         


        
7条回答
  •  孤独总比滥情好
    2021-02-04 13:53

    >>> import re
    >>> s = 'picture_page = "http://distilleryimage2.instagram.com/da4ca3509a7b11e19e4a12313813ffc0_7.jpg"'
    >>> re.findall(r'\/([a-zA-Z0-9_]*)\.[a-zA-Z]*\"$',s)[0]
    'da4ca3509a7b11e19e4a12313813ffc0_7'
    >>> re.findall(r'([a-zA-Z]*)\"$',s)[0]
    'jpg'
    

提交回复
热议问题