使用Python進行http POST請求

1、使用requests模塊

import request

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


2、使用urllib2模塊

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()




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章