urllib模組可以從網路取得資料(如同讀取一個網路檔案)
匯入urllib.request模組
import urllib.request
匯入模組後,呼叫urlopen()開啟網路檔案(url為網址串)
response = urllib.request.urlopen(url)
contents = response.read()


import requests
url = "https://ithelp.ithome.com.tw/articles/10265278 "
response = request.get(url)
| 屬性 | 說明 |
|---|---|
| text | 編碼的html標籤字串 |
| contents | 沒有編碼的位元組資料 |
| encoding | 取得HTML標籤字串的編碼 |
| status_code | 狀態碼 |