python http post数据

import HTMLParser
import httplib
from datetime import datetime
import time
import urllib
import urllib2,cookielib

#前面定义省略
def postData(self,name,password,key):
user="usernmae"
pwd="password"
cookie=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
urllib2.install_opener(opener)
params=urllib.urlencode({name:user,password:pwd,"key":key,"login":"true"})
headers={"Accept":"text/html","User-Agent":"IE","Content-Type":"application/x-www-form-urlencoded"}
website="www.haha.com"
path="/record.jsp"
conn=httplib.HTTPConnection(website)
print params
conn.request(method="POST",url=path,body=params,headers=headers)
r=conn.getresponse()
print r.status,r.reason
data=r.read()
print data
conn.close()

你可能感兴趣的:(html,jsp,python,IE)