step one:urllib获取网页基本信息:
#从urllib中导入request库
from urllib import request
#获取url
url="http://www.baidu.com"
#urlopen()获取网页信息
response = request.urlopen(url=url)
#读取网页内容
html = response.read()
#字符集转换为utf-8
html = html.decode("utf-8")
#打印输出
print(html)
运行结果:
其实三步就可以解决:
#从urllib中导入request库
import url