I am using Python to extract the filename from a link using rfind like below:
url = "http://www.google.com/test.php"
print url[url.rfind("/") +1 : ]
This works ok with links without a / at the end of them and returns "test.php". I have encountered links with / at the end like so "http://www.google.com/test.php/". I am have trouble getting the page name when there is a "/" at the end, can anyone help?
Cheers
Use [r]strip to remove trailing slashes:
If a wider range of possible URLs is possible, including URLs with ?queries, #anchors or without a path, do it properly with urlparse: