参考:https://www.cnblogs.com/Lands-ljk/p/5447127.html
方法1:直接传给urlopen方法
resp=urllib.request.urlopen("http://www.baidu.com")#直接请求
print(resp.getcode())#获取状态码,200表示成功
#或者str = resp.read()
#print(str)
方法2:添加data、httpheader,然后传送给request方法
resp2=urllib.request.Request("http://www.baidu.com")#创建request方法
resp2.add_header('a','1')#添加数据
resp2.add_header('Host','www.baidu.com')#添加请求表头
r = urllib.request.urlopen(resp2)#发送请求获取结果
print(r)
方法3:添加特殊情景的处理器