Python Beauty Soup Find()返回AttributeError

Python Beauty Soup Find()返回AttributeError,python,for-loop,beautifulsoup,Python,For Loop,Beautifulsoup,我的网页设置如下: //a bunch of container divs.... 两个print语句都成功执行,因此第二个语句告诉我,我至少已经进入了for循环。但是,我得到了错误 File "scrapeRecipe.py", line 40, in <module> name = tag.find("div", {"class": "name"}).text AttributeError: 'NoneType' object has no attribute 'te

我的网页设置如下:

//a bunch of container divs....

两个print语句都成功执行,因此第二个语句告诉我,我至少已经进入了for循环。但是,我得到了错误

File "scrapeRecipe.py", line 40, in <module>
    name = tag.find("div", {"class": "name"}).text
AttributeError: 'NoneType' object has no attribute 'text'
文件“scraprecipe.py”,第40行,在
name=tag.find(“div”,“class”:“name”}).text
AttributeError:“非类型”对象没有属性“文本”

,我假设我的代码没有找到任何类类型等于“name”或“score”的div。我对python一无所知。有人有什么建议吗

问题不在于您的
标记.find('div',…)
,而在于您的
汤.findAll('a')
。您正在提取每个
a
标记,甚至是那些没有子标记的标记,您正试图从中提取数据

根据您需要的外观,您还需要向
findAll
添加
class

aTag = soup.findAll('a', {'class': 'food'})
我相信它需要是“find”(“div)”,{'class':“name”}),但如果不是这样,它就可以工作
File "scrapeRecipe.py", line 40, in <module>
    name = tag.find("div", {"class": "name"}).text
AttributeError: 'NoneType' object has no attribute 'text'
aTag = soup.findAll('a', {'class': 'food'})