1. 程式人生 > >Python爬蟲學習(一)

Python爬蟲學習(一)

code time response utf path urllib quest ext .com

Python訪問網頁主要使用包urllib

打開網頁使用

urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) 

例子:

import urllib.request
response = urllib.request.urlopen(http://www.baidu.com)
html = response.read()
html = html.decode(utf-8) #對網頁進行解碼,顯示網頁源代碼
print(html)

Python爬蟲學習(一)