This is an alpha release.
Changes since 0.0.2a:
* Fixed lots of bugs. * Link instances may now be passed to .click_link() and .follow_link(). * Added a new example program, pypi.py. * ClientCookie 0.4.17 and pullparser 0.0.4b are now required (in fact, they always were, even though they didn't exist ;-).
Requires Python 2.2, ClientCookie >= 0.4.17 (note version!), ClientForm 0.1.x and pullparser >= 0.0.4b.
Stateful programmatic web browsing, after Andy Lester's Perl module WWW::Mechanize.
import re from mechanize import Browser
b = Browser() b.open("http://www.example.com/") # follow second link with element text matching regular expression response = b.follow_link(text_regex=re.compile(r"cheese\s*shop"), nr=1)
b.select_form(name="order") # Browser passes through unknown attributes (including methods) # to the selected HTMLForm (from ClientForm). b["cheeses"] = ["mozzarella", "caerphilly"] # (the method here is __setitem__) response2 = b.submit() # submit current form
response3 = b.back() # back to cheese shop response4 = b.reload()
for link in b.forms(): print form # .links() optionally accepts the keyword args of .follow_/.find_link() for link in b.links(url_regex=re.compile("python.org")): print link b.follow_link(link) # takes EITHER Link instance OR keyword args b.back()