Hi, Jeff,

twill's follow() method just calls mechanize's find_link() interface using a 
few different criteria until it finds one to follow. You can pass mechanize a 
regex object directly, though, to return a specific one:

# Import re and twill
import re
import twill.commands as t

# Goto the target site
t.go("http://www.google.com/search?q=twill";)

# Call the mechanize browser's find_link method, using the nr argument to 
specify which link to return
link_2 = t.browser._browser.find_link(text_regex=re.compile("Similar pages"), 
nr=2)
link_3 = t.browser._browser.find_link(text_regex=re.compile("Similar pages"), 
nr=3)

# Follow a link
t.browser.follow_link(link_3)

There are actually several arguments that find_link will accept: text, 
text_regex, name, name_regex, url, url_regex, tag, predicate, nr

For more info, see the docstring for find_link at: 
http://codespeak.net/svn/wwwsearch/mechanize/trunk/mechanize/_mechanize.py

Hope that helps,
Kevin
________________________________________
From: [EMAIL PROTECTED] [EMAIL PROTECTED] On Behalf Of Jeff Creem [EMAIL 
PROTECTED]
Sent: Friday, October 10, 2008 10:28 PM
To: [email protected]
Subject: [twill] 'Follow' the N'th link

I've got a page I am dealing with where there are (sometimes) two links
on the page with the same 'name'
Is there any robust way to have the 'follow' command go to anything
other than the first link or to programmatically iterate over all of the
links from the python interface?



_______________________________________________
twill mailing list
[email protected]
http://lists.idyll.org/listinfo/twill

CONFIDENTIALITY NOTE
The document(s) accompanying this e-mail transmission, if any, and the e-mail 
transmittal message containing information from Leapfrog Online Customer 
Acquisition, LLC is confidential or privileged. The information is intended to 
be for the use of the individual(s) or entity(ies) named on this e-mail 
transmission message. If you are not the intended recipient, be aware that any 
disclosure, copying, distribution or use of the contents of this e-mail is 
prohibited. If you have received this e-mail in error, please immediately 
delete this e-mail and notify us by telephone of the error.

_______________________________________________
twill mailing list
[email protected]
http://lists.idyll.org/listinfo/twill

Reply via email to