python + urllib 获取百度首页html
urllib库是python自带的库,不需要安装。
# coding = utf-8
from urllib.request import urlopen
# 获取html
html = urlopen('http://www.baidu.com/')
# 获取的html内容是字节,将其转化为字符串
html_text = bytes.decode(html.read())
# 打印html内容
print(html_text)
python + urllib 获取百度首页html
urllib库是python自带的库,不需要安装。
# coding = utf-8
from urllib.request import urlopen
# 获取html
html = urlopen('http://www.baidu.com/')
# 获取的html内容是字节,将其转化为字符串
html_text = bytes.decode(html.read())
# 打印html内容
print(html_text)