Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>br.follow_link</code> takes either a <code>Link</code> object or a keyword arg (such as <code>nr=0</code>). </p> <p><code>br.links()</code> lists all the links.</p> <p><code>br.links(url_regex='...')</code> lists all the links whose urls matches the regex.</p> <p><code>br.links(text_regex='...')</code> lists all the links whose link text matches the regex.</p> <p><code>br.follow_link(nr=num)</code> follows the <code>num</code>th link on the page, with counting starting at 0. It returns a response object (the same kind what br.open(...) returns)</p> <p><code>br.find_link(url='...')</code> returns the <code>Link</code> object whose <code>url</code> exactly equals the given url.</p> <p><code>br.find_link</code>, <code>br.links</code>, <code>br.follow_link</code>, <code>br.click_link</code> all accept the same keywords. Run <code>help(br.find_link)</code> to see documentation on those keywords.</p> <p><strong>Edit:</strong> If you have a target url that you wish to follow, you could do something like this:</p> <pre><code>import mechanize br = mechanize.Browser() response=br.open("http://www.example.com/") target_url='http://www.rfc-editor.org/rfc/rfc2606.txt' for link in br.links(): print(link) # Link(base_url='http://www.example.com/', url='http://www.rfc-editor.org/rfc/rfc2606.txt', text='RFC 2606', tag='a', attrs=[('href', 'http://www.rfc-editor.org/rfc/rfc2606.txt')]) print(link.url) # http://www.rfc-editor.org/rfc/rfc2606.txt if link.url == target_url: print('match found') # match found break br.follow_link(link) # link still holds the last value it had in the loop print(br.geturl()) # http://www.rfc-editor.org/rfc/rfc2606.txt </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload