python爬取網頁內容

'''
第一個示例:簡單的網頁爬蟲

'''

import urllib.request

#網址
url = "http://www.chinadaily.com.cn/a/201906/20/WS5d0acc47a3103dbf1432936b.html"

#請求
request = urllib.request.Request(url)

#爬取結果
response = urllib.request.urlopen(request)

data = response.read()

#設置解碼方式
data = data.decode('utf-8')

#打印結果
print(data)

#打印爬取網頁的各類信息

print(type(response))
print(response.geturl())
print(response.info())
print(response.getcode())

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章