用BS爬取网页内容之后标签属性一直出错,显示AttributeError: 'NoneType' object has no attribute 'text'
我用print在循环之前试过是可以成功提取出文本内容的,不知道为什么在循环里就不行。求大神解惑!
#s = content[0].find('h5',class_="result-sub-header")
#print(s.text.strip())
#遍历content,取出结果
#因为find_all返回的是一个list,再对list用find_all时,需要指定元素[0]
for i in range(len(content)):
#提取标题
t = content[i].find('a',class_="title")
title = t.text.strip()
#提取链接
url = 'https://www.forrester.com'+t['href']
#提取摘要
s = content[i].find('h5',class_="result-sub-header")
summary = s.text.strip()
#将提取的内容放在列表paper中
paper = [title,'Cloud Migration',url,summary]
#把每个paper加到paperlist
paperlist.append(paper)