【发布时间】:2020-01-06 14:56:56
【问题描述】:
我试图通过website 提取前 16 个粗体句子,然后再将它们插入数据框,但我一直遇到此错误。我已经尽我所能,我也是网络抓取的初学者。
import requests
import pandas as pd
from bs4 import BeautifulSoup
res = requests.get('https://www.nairaland.com/2838393/owe-ile-yoruba-some-lovely')
soup = BeautifulSoup(res.content,'html')
yoruba = []
for word in soup3.findAll('b'):
name = word.find('i')
yoruba.append(name.text)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-61-9d3379b8790a> in <module>
7 for word in soup3.findAll('b'):
8 name = word.find('i')
----> 9 yoruba1.append(name.text)
AttributeError: 'NoneType' object has no attribute 'text'
【问题讨论】:
-
错误告诉你到底哪里出了问题。
name,在第 9 行,是None。None没有text成员。您必须处理find失败的情况。
标签: python web-scraping