爬虫学习笔记第二天(urllib库)
1.urllib库(python自带的内置HTTP请求库):request模块(模拟发送请求);error(异常处理模块);parse(工具模块,处理URL);robotparser(识别网站的robots.txt文件)。 1.1 https://docs.python.org/3/library/urllib.request.html 官方手册。request模块:urlopen()方法,网站抓取,返回一个HTTPResponse类型的对象,该对象有read(),readinto(),getheader(name),getheaders(),fileno()等方法和msg,versuin,status,reason,debuglevel,closed等属性。,urlopen的API:urllib.request.urlopen(url,data=None,[timeout,]*,cafile=None.capath=None,cadefault=False,context=None)>>>>>>Request()类,返回一个request类型的对象,class urllib.request.Request(url,data=None,headers={},origine_req_host=None,unverifiable=False,method=None)>>>>>