NoneType对象没有属性' text'?

时间:2017-10-20 20:40:32

标签: python-3.x beautifulsoup

我想为一些艺术家wikipedias刮掉信息框。但我继续得到无属性错误。我做错了什么?

from bs4 import BeautifulSoup
from urllib.request import urlopen
url= "http://en.wikipedia.org/wiki/The_Beatles"

page = urlopen(url)
soup = BeautifulSoup(page.read(), "lxml")
table = soup.find('table', class_='infobox vcard plainlist')
result = {}
exceptional_row_count = 0
for tr in table.find_all('tr'):
    if tr.find('th'):
        result[tr.find('th').text] = tr.find('td').text
    else:
        exceptional_row_count += 1
if exceptional_row_count > 1:
    print ('WARNING ExceptionalRow>1: ', table)
print (result)

错误在这一行:

---> 13         result[tr.find('th').text] = tr.find('td').text
AttributeError: 'NoneType' object has no attribute 'text'

0 个答案:

没有答案