world —basic and digest authentication, redirections,
cookies and more.
?urllib.request.urlopen()方法实现了打开url,并返回一个http.client.HTTPResponse对象,通过http.client.HTTPResponse的read()方法,获得response body,转码最后通过print()打印出来.
urllib.request.urlopen(url, data=None,
[timeout, ]***, cafile=None, capath=None, cadefault=Fals
e, context=None)For HTTP and HTTPS URLs, this function
returns a http.client.HTTPResponseobject slightly
modified.< 出自:
https://http://www.77cn.com.cn/3/library/urllib.request.html >
?decode('utf-8')用来将页面转换成utf-8的编码格式,否则会出现乱码二模拟浏览器爬取信息
在访问某些网站的时候,网站通常会用判断访问是否带有头文件来鉴别该访问是否为爬虫,用来作为反爬取的一种策略。
先来看一下Chrome的头信息(F12打开开发者模式)如下: