AttributeError: 'NoneType' object has no attribute 'get_text'
BeautifulSoup для парсинга html таблицы
from bs4 import BeautifulSoup
path = 'D://Downloads//htmltable.htm'
with open(path, encoding='utf-8') as fp:
soup = BeautifulSoup(fp, 'html.parser')
table = soup.find('table')
output = []
for spec in table.find_all('tbody'):
rows = spec.find_all('tr', {'style': 'text-align:center; font-size: 12px;'})
for row in rows:
output.append({
'specs': row.find('td').get_text(),
'name': row.find('td', attrs={'style': 'text-align:center; font-size: 10px;'})
})
print(output)
выдаёт
[{'specs': <td title="Радиосвязь">11.02.10</td>, 'name': <td style="text-align:center; font-size: 10px;">Техник</td>}]
при использовании .get_text() у 'specs' выдает
{'specs': '11.02.10', 'name': <td style="text-align:center; font-size: 10px;">Техник</td>}
но при использовании .get_text() у 'name' выдает
AttributeError: 'NoneType' object has no attribute 'get_text'