Python ';非类型';对象没有属性';文本';错误
因此,我使用xml将数据传输到我的数据库,4个表工作正常,但突然出现错误,我不知道如何解决它:Python ';非类型';对象没有属性';文本';错误,python,python-3.x,Python,Python 3.x,因此,我使用xml将数据传输到我的数据库,4个表工作正常,但突然出现错误,我不知道如何解决它: tables = soup.find_all('tabela_specjalnosci') # for each tabela_specjalnosci looks like there is 2 nested corresponding tags tags = ['id', 'nazwa'] # initialize empty dataframe df = p
tables = soup.find_all('tabela_specjalnosci')
# for each tabela_specjalnosci looks like there is 2 nested corresponding tags
tags = ['id', 'nazwa']
# initialize empty dataframe
df = pd.DataFrame()
# iterate over each tabela_specjalnosci and extract each tag and append to pandas dataframe
for table in tables:
all = map(lambda x: table.find(x).text, tags) # everything fine
df = df.append([all], ignore_index=True)
# insert tags as columns
df.columns = tags
# add schedule row by row to database
for row in df.iterrows():
object = Specjalnosc(row[1])
db.session.add(object)
db.session.commit()
上面的代码运行良好,但下一个代码突然不行
tables = soup.find_all('tabela_studia')
# for each tabela_studia looks like there is 2 nested corresponding tags
tags = ['id', 'nazwa']
# initialize empty dataframe
df = pd.DataFrame()
# iterate over each tabela_studia and extract each tag and append to pandas dataframe
for table in tables:
all = map(lambda x: table.find(x).text, tags) #'NoneType' object has no attribute 'text'
df = df.append([all], ignore_index=True)
# insert tags as columns
df.columns = tags
# add schedule row by row to database
for row in df.iterrows():
object = Studia(row[1])
db.session.add(object)
db.session.commit()
我添加的xml如下所示:
<tabela_specjalnosci data-aktualizacji="1474562975">
<ID>0</ID>
<NAZWA><ogólna></NAZWA>
</tabela_specjalnosci>
0
第二点:
<tabela_studia data-aktualizacji="1474563008">
<ID>1</ID>
<NAZWA>stac. magisterskie jednolite</NAZWA>
</tabela_studia>
1.
斯塔克。马吉斯特斯基陨石
有什么问题吗?
表。查找(x)
可以返回无
。特别是当XML文件包含单个标记时,如
。。。你说“突然不”是什么意思?它适用于第一个,而不适用于第二个,或者相反?是的,代码适用于tabela_specjalnosci,而tabela_studia突然不行。案例结束,问题是我的打字错误。我想是时候睡觉了。find(x)可以返回None
。特别是当XML文件包含单个标记时,如
。。。你说“突然不”是什么意思?它适用于第一个,而不适用于第二个,或者相反?是的,代码适用于tabela_specjalnosci,而tabela_studia突然不行。案例结束,问题是我的打字错误。我想该睡觉了