[Tutor] Fill in a web form

Michael Janssen mi.janssen at gmail.com
Sat Mar 18 18:09:20 CET 2006


On 3/18/06, David Holland <davholla2002 at yahoo.co.uk> wrote:

> Is there a way in python to automatically put values in a web page ?  For
> example I used to travel on a train (I live in the UK) that is always late.
> Is there a way to automatically to do this ?
> I can't think of  how to do it.

You don't "fill" the form fields, but rather you perform the same
action the browser would performs with a filled form.

You must look into the html-form-tag and its action- and
method-attributes. "Action" is the url to the script receiving the
filled form. Method tells the browser how to send the data: "get"
means to generate an url like "www.google.com?q=python', ie an url
with the content of the form. Method "post" means to send the data
"inline". urllib2.urlopen handles this (its data parameter for "post"
data). Perhaps urllib.urlencode is of interest for you (before
generating a get-url, urlencode the data, so that it renders a sane
url).

This answere is a bit short and might leaves you with a lot of open
questions. If so, ask :-)

regards
Michael


More information about the Tutor mailing list