简体   繁体   中英

extract image name from url using python

i want to extract image name from Links Like this 2 Links

url1 = 'https://vignette.wikia.nocookie.net/warframe/images/1/17/AshNewLook.png/revision/latest?cb=20141124022921'
url2 = 'https://vignette.wikia.nocookie.net/warframe/images/b/b5/BaruukIcon272.png/revision/latest?cb=20181219151057'

i tried using os.path.basename but it doesn't work

all i want to extract is image name from Links

'AshNewLook.png' from Page 1

'BaruukIcon272.png' from Page 2

Note: Links Works Without the last part

example:

url1 = 'https://vignette.wikia.nocookie.net/warframe/images/1/17/AshNewLook.png/revision/latest?cb=20141124022921' url2 = 'https://vignette.wikia.nocookie.net/warframe/images/1/17/AshNewLook.png'

url1 will open same page as url2

最简单的方法可能是用/字符分割 url 并从末尾取出第三个元素:

pic = url1.split('/')[-3]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM