postimport urlliimport urllib
#post数据
value = {}
value['username']='aaaa'
value['password']='123123'
data = urllib.urlencode(value)
#添加header
request = urllib2.Request("http://localhost/client.php")
request.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0')
request.add_header('User-ccc','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0')
#response = urllib2.urlopen('http://www.baidu.com', timeout=10)
#response = urllib2.urlopen('http://www.baidu.com',data, 10)
response = urllib2.urlopen(request,data)
print response.read()
get
import urllib
import urllib2
values = {}
values['username'] = "1016903103@qq.com"
values['password'] = "XXXX"
data = urllib.urlencode(values)
url = "http://passport.csdn.net/account/login"
geturl = url + "?" + data
request = urllib2.Request(geturl)
response = urllib2.urlopen(request)
print response.read()