Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2561

Re: using python to post data to a form

Date 2011-04-04 07:01 -0400
From Corey Richardson <kb1pkl@aim.com>
Subject Re: using python to post data to a form
References <4D9958FA.8080606@tysdomain.com>
Newsgroups comp.lang.python
Message-ID <mailman.0.1301914894.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 04/04/2011 01:36 AM, Littlefield, Tyler wrote:
> Hello:
> I have some data that needs to be fed through a html form to get 
> validated and processed and the like. How can I use python to send data 
> through that form, given a specific url? the form says it uses post, but 
> I"m not really sure what the difference is. would it just be:
> http://mysite.com/bla.php?foo=bar&bar=foo?
> If so, how do I do that with python?
> 

import urllib
import urllib2

url = "http://www.foo.com/"
data = {"name": "Guido", "status": "BDFL"}

data = urllib.urlencode(data)
request = urllib2.Request(url, data)
response = urllib2.urlopen(request)

page = response.read()

So yeah, passing in a Request object to urlopen that has some
urlencode'ed data in it.
-- 
Corey Richardson

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: using python to post data to a form Corey Richardson <kb1pkl@aim.com> - 2011-04-04 07:01 -0400

csiph-web