1. 程式人生 > >Python 3.6 實現簡單的爬蟲

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))