python发送http请求包:httplib,urllib,urllib2,urllib3,requests

httplib:
1、创建连接
conn = httplib.HTTPSConnection(“www.baidu.com”)
2、发送请求
conn.request(“GET”, “/”)
3、接受请求
conn.getresponse()
urllib:
1、构建数据包
data = urllib.urlencode({‘key’: “value”})
2、发送get请求(?衔接参数)
response=urllib.urlopen(“www.baidu.com?%s” % data)
3、发送post请求
response=urllib.urlopen(“www.baidu.com” , data)
4、处理结果
response.read()
urllib2:

urllib3:

requests:
1、发送请求
response = requests.get(“www.baidu.com”)
2、处理请求
response.status_code response.content

你可能感兴趣的:(python,python,http,httplib,urllib,request)