使用 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 中也提供了类似的模块。