所以我使用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 = 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>
和第二个:
<tabela_studia data-aktualizacji="1474563008">
<ID>1</ID>
<NAZWA>stac. magisterskie jednolite</NAZWA>
</tabela_studia>
这里有什么问题吗?