如何解决Python-美丽的汤4-'NavigableString'对象没有属性'find_all'
我有以下代码:
for route in parsedXml.find_all('route'):
print(dataCheck(route.find('routesectionref')))
for routeSection in parsedXml.find(id = dataCheck(route.find('routesectionref'))):
for routeLink in routeSection.find_all('routelink'):
print(routeLink)
哪个返回错误:
Exception has occurred: AttributeError
'NavigableString' object has no attribute 'find_all'
问题在于“路线”是“ bs4.element.Tag”。 “ routeSection”是“ bs4.element.NavigableString”。如何修改我的“ routeSection”变量声明以返回“ bs4.element.Tag”?
解决方法
'NavigableString' object has no attribute 'find_all'
可能正在发生,因为BeautifulSoup解析的实际上是一个字符串(或包含一个字符串),而不是HTML / XML标记。
Ref:“ AttributeError: 'NavigableString' object has no attribute 'foo'
-这通常是因为您将字符串当作标签来对待。您可能会遍历列表,期望当列表中除标签外不包含任何其他内容它实际上包含标签和字符串。”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。