获取网页title(还有一坑未填)

 1     def getTitle(self,url):
 2         #get title
 3         title = 'time out'
 4         try:
 5             self.res = requests.get(url,timeout=5)
 6             
 7 
 8             soup = BeautifulSoup(self.res.text, 'lxml')
 9             
10             title = soup.title.text
11            
12         except Exception:
13             title = self.res.text
14         
15         return title
原文地址:https://www.cnblogs.com/xiaobaichuangtianxia/p/9772844.html