使用Python進行http POST請求

一、使用requests模塊
python

import request

url='http://www.xxx.com/xxx'
data={'username':'zhangsan','password':'zhangsanpw'}
r=requests.post(url,data=data)
print r.text


二、使用urllib2模塊ide

import urllib2
import urllib

url='http://www.xxx.com/xxx'
data={'username':'zhangsan','password':'zhangsanpw'}
r = urllib2.Request(url,urllib.urlencode(data))
result = urllib2.urlopen(req)
print result.read()
相關文章
相關標籤/搜索