Take the 2-minute tour ×

My general question : How could i submit a form and then get response from website with a python program ?

My specific : I want to send some thing like Ajax XHR send to a web file and get response from it , problematically .

  • I don't want to use any browser and do it in the code like this link.

  • I have read this articles and they just make me confused and can't find good documented about it.

share|improve this question
you wanna get the response "problematically"??? What is that supposed to mean? –  IcyFlame Apr 27 '13 at 8:46
Tell us more. Are you trying to access a GET or POST website, does it have an API etc –  Xaranke Apr 27 '13 at 8:51
I want to send or POST a XHR request to a webpage and get response which that could be save as a file with a response.I want to analyse that response in my program. –  Golix Apr 27 '13 at 8:58
Why not just use urllib2? –  onon15 Apr 27 '13 at 9:01
Okey let my try once more.thanks. –  Golix Apr 27 '13 at 9:04

2 Answers 2

Requests is very easy too!

Here is the example from their homepage pertaining to POSTing forms

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print r.text
"form": {
"key2": "value2",
"key1": "value1"
share|improve this answer

Simply use urllib2

import urllib
import urllib2 

data = {
    'field1': 'value1',
    'field2': 'value2',

req = urllib2.Request(url="http://some_url/...",
response = urllib2.urlopen(req)
the_page = response.read()
share|improve this answer

Your Answer


