Python写网络爬虫-Urllib库
1、 首先,需要导入对应模块,所以,需要输入以下代码导入urllib.request:>>>import urllib.request
2、 导入模块之后,需要使用urllib.request.urlopen打开并爬取一个网页,以百度首页(http://www.baidu.com)为例,将爬取到的网页赋给变量file:>>>file = urllib.request.urlopen("http://www.baidu.com")
3、 此时,需要使用file.read()方法读取全部内容:>>>data = file.read()>>>data
