How to fill a form
John J. Lee
jjl at pobox.com
Thu Aug 17 16:29:57 EDT 2006
Sulsa <sulsa at gazeta.pl> writes:
> On Tue, 15 Aug 2006 03:37:02 -0000
> Grant Edwards <grante at visi.com> wrote:
>
> > On 2006-08-15, Sulsa <sulsa at gazeta.pl> wrote:
> >
> > > I want to fill only one smiple form so i would like not to use
> > > any non standard libraries.
> >
> > Then just send the HTTP "POST" request containing the fields
> > and data you want to submit.
>
> but i don't know how to post these data if i knew there there would
> be no topic.
Something like this (UNTESTED, and I can never remember all the
details, which are fiddlier than they may look):
import urllib, urllib2
query = urllib.urlencode([
("username", "sulsa"), ("password", "sulsa"),
("redirect", ""), ("login", "Login"),
])
r = urllib2.urlopen("http://example.com/login.php", query)
print r.read()
Note that urllib and urllib2 both, as their main job in life, open
URLs. urllib also has miscellaneous functions related to URLs &c. I
use urllib2 above because I know it better and because it can handle
some stuff that urllib doesn't (it's designed more for extensibility
than is urllib).
John
More information about the Python-list
mailing list