Вы можете использовать br.links()
для генерации всех таких ссылок, а затем использовать list(...)[-1]
для выбора последней:
lastLink = list(br.links(text_regex=re.compile("Display charges")))[-1]
Например:
In [29]: import mechanize
In [30]: import re
In [31]: br=mechanize.Browser()
In [32]: br.open('http://www.example.com')
Out[32]: <response_seek_wrapper at 0xa2b59ec whose wrapped object = <closeable_response at 0xa2b554c whose fp = <socket._fileobject object at 0xa3143ac>>>
In [33]: br.links()
Out[33]: <generator object __call__ at 0xa289af4>
In [34]: list(br.links())
Out[34]:
[Link(base_url='http://www.iana.org/domains/example/', url='/', text='Homepage[IMG]', tag='a', attrs=[('href', '/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/domains/', text='Domains', tag='a', attrs=[('href', '/domains/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/numbers/', text='Numbers', tag='a', attrs=[('href', '/numbers/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/protocols/', text='Protocols', tag='a', attrs=[('href', '/protocols/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/about/', text='About IANA', tag='a', attrs=[('href', '/about/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/go/rfc2606', text='RFC 2606', tag='a', attrs=[('href', '/go/rfc2606')]),
Link(base_url='http://www.iana.org/domains/example/', url='/about/', text='About', tag='a', attrs=[('href', '/about/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/domains/', text='Domains', tag='a', attrs=[('href', '/domains/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/protocols/', text='Protocols', tag='a', attrs=[('href', '/protocols/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/numbers/', text='Number Resources', tag='a', attrs=[('href', '/numbers/')]),
Link(base_url='http://www.iana.org/domains/example/', url='http://www.icann.org/', text='Internet Corporation for Assigned Names and Numbers', tag='a', attrs=[('href', 'http://www.icann.org/')]),
Link(base_url='http://www.iana.org/domains/example/', url='mailto:iana@iana.org?subject=General%20website%20feedback', text='iana@iana.org', tag='a', attrs=[('href', 'mailto:iana@iana.org?subject=General%20website%20feedback')])]
In [35]: list(br.links(text_regex=re.compile("About")))
Out[35]:
[Link(base_url='http://www.iana.org/domains/example/', url='/about/', text='About IANA', tag='a', attrs=[('href', '/about/')]),
Link(base_url='http://www.iana.org/domains/example/', url='/about/', text='About', tag='a', attrs=[('href', '/about/')])]