Python 3.6 实现简单的爬虫

python作为一种新锐语言,他的更新是非常的快的。

3.x与2.x相比,它整合了urllib,urllib2,urllib3等一系列的模块,在3.x里,实现一个爬取网页简易的程序如下

# -*- coding: utf-8 -*-
import urllib.request
url='http://www.baidu.com/'
def getHtml(url):
    page=urllib.request.urlopen(url)
    html=page.read().decode(encoding='utf-8',errors='strict')
    return html
print(getHtml(url))