美丽的汤-AttributeError:'NoneType'对象没有属性'text'

时间:2019-12-29 17:01:45

标签: beautifulsoup

#Used headers/agent because the request was timed out and asking for an agent. 
#Using following code we can fake the agent.
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'}
response = requests.get("https://www.zomato.com/bangalore/microbreweries",headers=headers)

content = response.content
soup = BeautifulSoup(content,"html.parser")

top_rest = soup.find_all("div",attrs={"class": "bb0 collections-grid col-l-16"})
list_tr = top_rest[0].find_all("div",attrs={"class": "col-s-8 col-l-1by3"})

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)
<ipython-input-21-87790cd92287> in <module>
      2 for tr in list_tr:
      3     dataframe ={}
----> 4     dataframe["brewery_name"] = (tr.find("div",attrs={"class": "res_title zblack bold nowrap"})).text.replace('\n', ' ')
      5     dataframe["brewery_address"] = (tr.find("div",attrs={"class": "nowrap grey-text fontsize5 ttupper"})).text.replace('\n', ' ')
      6     dataframe["beer_type"] = (tr.find("div",attrs={"class":"nowrap grey-text"})).text.replace('\n', ' ')

AttributeError: 'NoneType' object has no attribute 'text'

0 个答案:

没有答案