Skip to content

Commit 79c2f7f

Browse files
committed
expand docs
1 parent 6cf4bdd commit 79c2f7f

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

README.rst

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ Homepage: `http://pyrobot.readthedocs.org/ <http://pyrobot.readthedocs.org/>`_
4141
lyrics.text # \n[Verse 1]\nYou suck my blood like a leech...
4242
4343
PyRobot combines the best of two excellent Python libraries:
44-
Requests and BeautifulSoup. PyRobot represents browser sessions using
45-
Requests and HTML responses using BeautifulSoup, transparently exposing
46-
methods of both libraries:
44+
`Requests <http://docs.python-requests.org/en/latest/>`_ and
45+
`BeautifulSoup <http://www.crummy.com/software/BeautifulSoup/>`_.
46+
PyRobot represents browser sessions using Requests and HTML responses
47+
using BeautifulSoup, transparently exposing methods of both libraries:
4748

4849
.. code-block:: python
4950
@@ -67,3 +68,32 @@ methods of both libraries:
6768
# <span class="mega-octicon octicon-checklist"></span>
6869
# ...
6970
71+
PyRobot also includes tools for working with forms, inspired by
72+
`WebTest <https://github.com/Pylons/webtest>`_ and `Mechanize <http://wwwsearch.sourceforge.net/mechanize/>`_.
73+
74+
.. code-block:: python
75+
76+
from pyrobot import Browser
77+
browser = RoboBrowser()
78+
79+
# Get the signup form
80+
signup_form = browser.get_form(class_='signup')
81+
signup_form # <RoboForm user[name]=, user[email]=, ...
82+
83+
# Inspect its values
84+
signup_form['authenticity_token'].value # 6d03597 ...
85+
86+
# Fill it out
87+
signup_form['user[name]'] = 'python-robot'
88+
signup_form['user[user_password]'] = 'secret'
89+
90+
# Serialize it to JSON
91+
signup_form.serialize() # {'data': {'authenticity_token': '6d03597...',
92+
# 'context': '',
93+
# 'user[email]': '',
94+
# 'user[name]': 'python-robot',
95+
# 'user[user_password]': ''}}
96+
97+
# And submit
98+
browser.submit_form(signup_form)
99+

0 commit comments

Comments
 (0)