Automate action with mechanize

Mechanize is a great tool for web ressources access . It simulates a web browser. This library is part of zope.testbrowser so if you have zope.testbrowser you have mechanize.

A little exemple : login in a plone portal

## first log to portal

>>> br = mechanize.Browser()

>>> br.open(‘http://localhost:8080/plone/login_form’)
>>> br.forms()[0].find_control(‘__ac_name’) = ‘admin’
>>> br.forms()[0].find_control(‘__ac_password’) = ‘admin’
>>> br.open(br.forms()[0].click())
<response_seek_wrapper …
>>> ‘admin’ in br._response.read()
True

And as you can simulate navigation zope.testbrowser by clicking on links,submit forms … A handy tool to perform operations on the tedious zmi.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.