1. 生成request对象
req = urllib2.Request('http://www.baidu.com')
通过调用urlopen并传入Request对象,将返回一个相关请求response对象
response = urllib2.urlopen(req)
应答对象如同一个文件对象,所以你可以在Response中调用.read()
the_page = response.read()
2.表单:一般的HTML表单,data需要编码成标准形式。然后做为data参数传到Request对象
data = urllib.urlencode(values)
3.模拟报头
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header ={'user_agent':user_agent}
4.Httperror/Urlerror
服务器上每一个HTTP 应答对象response包含一个数字"状态码"。
有时状态码指出服务器无法完成请求。默认的处理器会为你处理一部分这种应答。
5.