我有下面的XML文件:类型错误:“NoneType”对象不是可调用的Python用BeautifulSoup XML
<user-login-permission>true</user-login-permission>
<total-matched-record-number>15000</total-matched-record-number>
<total-returned-record-number>15000</total-returned-record-number>
<active-user-records>
<active-user-record>
<active-user-name>username</active-user-name>
<authentication-realm>realm</authentication-realm>
<user-roles>Role</user-roles>
<user-sign-in-time>date</user-sign-in-time>
<events>0</events>
<agent-type>text</agent-type>
<login-node>node</login-node>
</active-user-record>
有许多记录 我试图从标签获取值,并将其保存在不同的文本使用以下代码文件:
soup = BeautifulSoup(open("path/to/xmlfile"), features="xml")
with open('path/to/outputfile', 'a') as f:
for i in range(len(soup.findall('active-user-name'))):
f.write ('%s\t%s\t%s\t%s\n' % (soup.findall('active-user-name')[i].text, soup.findall('authentication-realm')[i].text, soup.findall('user-roles')[i].text, soup.findall('login-node')[i].text))
我得到的错误类型错误:“NoneType”对象不可调用Python和BeautifulSoup XML为线:对于i在范围(LEN(soup.findall(“活性用户名” ))):
任何想法可能会导致这种情况?
谢谢!
优化我的脚本2S,谢谢! – user2633192