HELP with HTTPLIB/URLLIB

Moshe Zadka moshez at math.huji.ac.il
Sun Jun 11 16:03:07 EDT 2000


On Sun, 11 Jun 2000, Alan Alper wrote:

> I need to duplicate the action of a browser POSTing form data to a server.
> GET is easy, but I don't know how to do POST. Any and all help, preferably
> with examples would be welcome.  Essentially, I'm trying to write a small
> agent to fetch classified ad data from several newspaper websites for me so
> that I don't need to visit the sites manually.  I have no clue how to do a
> POST.

urllib.urlopen has a second argument, which is data for a form request.
You can turn dictionaries into data by encoding them: urllib.urlencode.
So, here's a post example:

urllib.urlopen("http://foo.bar.com", urllib.urlencode({'name': 'moshe'})

With a little work you can wrap up this function to be much easier to use.
(Think keyword parameters)
--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list