How to remove the last part of a URL after the last slash (/) in Python

1 Answer

0 votes
url = "http://www.website.com/abc/xyz"
   
url = url.rsplit('/',1)[0]
 
print(url)  
 
  
  
'''
run:

http://www.website.com/abc
  
'''

 



answered Feb 19, 2020 by avibootz

Related questions

3 answers 356 views
1 answer 261 views
1 answer 210 views
2 answers 284 views
1 answer 193 views
1 answer 170 views
...