Simulating WWW button press

Jan Dries jdries at mail.com
Mon Jan 1 21:31:58 EST 2001


Lutz Schroeer wrote:
> 
> Jan Dries <jdries at mail.com> wrote in
> <mailman.978398162.28694.python-list at python.org>:
> 
> Well, maybe this snippet of the (very unreadable) source is large enough.
> 
> <form ACTION="/dyx-pv/onepagebatch/lV21.zip" ENCTYPE=x-www-form-encoded
> METHOD=POST>

Oops, a zip-file. That's not making things easier. Transporting it to
your machine will not be so difficult, but construction the actual
zip-file from the respons might present you a few surprises. I've never
worked with programmed http requests that returned anything other than
plain text of html though, so I'm afraid I can't help you if you run in
trouble here.

> 
> <INPUT NAME="zipallpage" TYPE="submit" VALUE="Get all files">
> </form>
> 
> I tried and read some more stuff and ended at the example 11.3.2 in the
> Library reference (1.5.2). Unfortunately my own
> version of this code doesn't work (it stucks after the getfile() ).

I assume you mean 11.4.2 (there's no getfile() in 11.3.2). Anyway, the
sample code in 11.4.2 is a good starting point, although reading the
code I think the line

  h.send(paramstring)

should be replaced by 

  h.send(params)

But you also do need to look for all the <INPUT> elements in the form
you mentioned above, because the value of all these elements must be
supplied as parameters to the POST action. 

> 
> Is my suggestion right that the base address for the submission is the
> same as the page's base address if the code defines nothing different?

If the URL in action starts with a /, the URL is relative to the server.
If it starts with http://, it's absolute, and if doesn't start with
either, it's relative to the page containing the form.
In your case, it's relative to the server, so you should change sample
11.4.2 to:

>>> h = httplib.HTTP("...") # (the server the page containging the form is on)
>>> h.putrequest("POST", "/dyx-pv/onepagebatch/lV21.zip")

> 
> Additionally I came to the conclusion that I seem to have to send a
> Content-Length header entry (the server replied me an error 411) but have
> no idea about the value.

You must provide a value for "Content-length" equal to the amount of
bytes sent in the post request, i.e. the size of the string you supply
to the send() method of your HTTP-object (as it is done in example
11.4.2).

> 
> To make it totally complicated the form is on a password protected page.
> So how do I send my username and passwd to the server?

I can't help you here either. I know some forms of authentication use
the "Authentication" header field in the http-request, but I have no
idea how to use it.

> 
> Maybe this informtion
> 
> (it's hard to express a quite complex problem in English which is not my
> native language)

I do speak German, presumably well enough to understand you, as long as
I can answer in English (or Dutch) (it's a bit hard for me to express
complex things in German :-)).

Jan




More information about the Python-list mailing list