IT源码网

python的get和post讲解

xmjava 2021年02月16日 编程语言 206 0
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'] = "[email protected]" 
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()

 

发布评论
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

python爬虫教程讲解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。