How to fill a form

Steve Holden steve at holdenweb.com
Mon Aug 14 22:22:40 EDT 2006


Sulsa wrote:
> I need to fill form from web site, the code for this form looks like
> this:
> 
> <form action="login.php" method="post" target="_top">
> 
> <input type="text" name="username" size="25" maxlength="40"
> class="post" />
> <input type="password" name="password" size="25" maxlength="25"
> class="post" />
> 
> <input type="hidden" name="redirect"
> value="" />
> <input type="submit" name="login" class="mainoption"
> value="Login" />
> 
> </form>
> 
> I can of course connect to a web site and download the form, i do it
> like this:
> 
> import  urllib2
> www = urllib2.urlopen("http://www.site.com/login.php")
> form_data= stronka.read()
> 
> or using httplib:
> 
> import httplib
> conn = httplib.HTTPConnection("www.site.com")
> conn.request("GET", "/login.php")
> data1 = conn.getresponse().read()
> 
> 
> but  i can't fill and send this form is there some simple way to do it?

I'd recommend you take a look at mechanize, see

   http://wwwsearch.sourceforge.net/mechanize/

and specifically at ClientForm, see

   http://wwwsearch.sourceforge.net/ClientForm/

These make it easy to perform browser-like accesses to forms-based web 
applications.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list