今天学习写爬虫,练习网址为http://blog.csdn.net/bo_wen_/article/details/50868339,做一个抓取每日最高最低温度的练习。在过程中遇到这样一个问题,代码所示:
# coding : UTF-8
import requests
from bs4 import BeautifulSoup
res = requests.get('http://www.weather.com.cn/weather/101190401.shtml')
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,"html5lib")
tt=soup.body.find_all('ul',class_= 't clearfix')
tt2 = tt.find_all('li')
print(tt2)
运行结果如下:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-60-2de0ac4bc00d> in <module>()
14
15 tt=soup.body.find_all('ul',class_= 't clearfix')
---> 16 tt2 = tt.find_all('li')
17 print(tt2)
D:\folder\envs\hh\lib\site-packages\bs4\element.py in __getattr__(self, key)
1805 def __getattr__(self, key):
1806 raise AttributeError(
-> 1807 "ResultSet object has no attribute '%s'. Yo