I’ve got a page with >=1 links with “Display charges” in the text.
I can find the first such link with
firstLink = br.find_link(text_regex=re.compile("Display charges"),nr=0)
I’d love to be able to find the final link. I hoped this would work
lastLink = br.find_link(text_regex=re.compile("Display charges"),nr=-1)
but in the case of only one matching link, it’s failing.
Please note: Python and mechanize beginner but have discovered help(mechanize.Browser) which was a big breakthrough 🙂
You could use
br.links()to generate all such links, then uselist(...)[-1]to pick off the last one:For example: