Python 获取页面title

#!/usr/bin/python
#coding=utf-8

#urllib2是python自带的模块,在python3.x中被改为urllib.request
import urllib.request
import re

page = urllib.request.urlopen('http://www.baidu.com')
html = page.read().decode('utf-8')
# Python3 findall数据类型用bytes类型
# or html=urllib.urlopen(url).read()

title=re.findall('(.+)',html)
print (title)

 

转载于:https://www.cnblogs.com/gqhwk/p/5364566.html

你可能感兴趣的:(Python 获取页面title)