python: urllib2 http post


/ Published in: Python
Save to your folder(s)

I see almost all GET, so this is handy to have around


Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2. import urllib,urllib2
  3.  
  4. url = 'http://www.commentcamarche.net/search/search.php3'
  5. parameters = {'Mot' : 'Gimp'}
  6.  
  7. data = urllib.urlencode(parameters) # Use urllib to encode the parameters
  8. request = urllib2.Request(url, data)
  9. response = urllib2.urlopen(request) # This request is sent in HTTP POST
  10. page = response.read(200000)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.