1. Urllib
Python内置的HTTP请求库
urllib.request············# 请求模块
urllib.error···············# 异常处理模块
urllib.parse··············# 提供了对url进行拆分、合并等处理方法
urllib.robotparser······# 针对网站的robots.txt文件进行识别,判断站点是否可爬取
1.1 不同Python版本Urllib库区别
HTTP请求测试站点:http://httpbin.org/post
# python2
import urllib2
response = urllib2.urlopen('http://www.baidu.com')
# python3
# urlopen在Python3,已被迁移到urllib.request库中
import urllib.request
response = urllib.request.urlopen('http://www.baidu.com') # byte类型
1.2 urlopen
urlopen
1.3 响应
响应
1.4 Request
Request
1.5 Handler
Handler
1.6 Cookie
Cookie
1.7 异常处理
异常处理
1.8 URL解析
urlparse
urlunparse
urljoin
urlencode