用python3读取百度首页
代码
- 爬取百度首页
import urllib.request
import urllib
url="http://www.baidu.com/"
html=urllib.request.urlopen(url)
content=html.read().decode('utf-8')
#html_text=bytes.decode(html.read())
#print(html_text)
print(content)
- 读取百度首页中的标题
在控制台输入pip install bs4
安装BeautifulSoup
from urllib.request import urlopen
from bs4 import BeautifulSoup as bf
html=urlopen("http://www.baidu.com/")
obj=bf(html