title: Submitting to a web form using python
body: <p>I have seen questions like this asked many many times but none are helpful</p>
  
  <p>Im trying to submit data to a form on the web ive tried requests, and urllib and none have worked</p>
  
  <p>for example here is code that should search for the [python] tag on SO:</p>
  
  <pre><code>import urllib
  import urllib2
  
  url = 'http://stackoverflow.com/'
  
  # Prepare the data
  values = {'q' : '[python]'}
  data = urllib.urlencode(values)
  
  # Send HTTP POST request
  req = urllib2.Request(url, data)
  response = urllib2.urlopen(req)
  
  html = response.read()
  
  # Print the result
  print html
  </code></pre>
  
  <p>yet when i run it i get the html soure of the home page</p>
  
  <p>here is an example of using requests:</p>
  
  <pre><code>import requests
  
  data= {
      'q': '[python]'
      }
  r = requests.get('http://stackoverflow.com', data=data)
  
  print r.text
  </code></pre>
  
  <p>same result! i dont understand why these methods arent working i've tried them on various sites with no success so if anyone has successfully done this please show me how!</p>
  
  <p>Thanks so much!  </p>