使用 urllib.request 下載簡單的 Web 內容

標準庫模組 urllib.request 可用於下載 Web 內容:

from urllib.request import urlopen

response = urlopen('http://stackoverflow.com/questions?sort=votes')    
data = response.read()

# The received bytes should usually be decoded according the response's character set
encoding = response.info().get_content_charset()
html = data.decode(encoding)

Python 2 中也提供了類似的模組。