<p>I am using Python to extract the filename from a link using rfind like below:</p>

<pre><code>url = "http://www.google.com/test.php"

print url[url.rfind("/") +1 : ]
</code></pre>

<p>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 "<a href="http://www.google.com/test.php/" rel="nofollow noreferrer">http://www.google.com/test.php/</a>".  I am have trouble getting the page name when there is a "/" at the end, can anyone help?</p>

<p>Cheers</p>

You could use
```
```
print url[url.rstrip("/").rfind("/") +1 : ]
```
```