I've a URL like this
url = 'https://www.example.com/contents/6641345'
I want to extract id at the last of url you can say the interger part from the above string
I tried the solution provided https://stackoverflow.com/a/11339230/2391469 but it gives error you can test that answer as well by removing the starting numeric values and putting some where else in the code, that code will throw an error
can anybody help me to get this id?
You can either split the string
>>> url.split('/')[-1]
'6641345'
Or use a regex
>>> import re
>>> re.findall('\d+', url)
['6641345']
Assuming the urls are always of the format that you showed in your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With