【发布时间】:2015-09-05 12:56:00
【问题描述】:
<TAGS>
<PARENT ID="Parent Id">
<MID>
<CHILD ATTR="Child Value"
我有一段代码正在为某些 xml 选择与“子值”相对应的所有属性值。
我还需要“父值”,将这两个项目关联起来,以备将来使用。
我的代码当前定位并检索子值,但我无法从父 ID 获取值。正确的语法是什么?
目前的代码是这样的:
taglist = []
for parent in soup.find_all('tags'):
for each in parent.find_all('child'):
taglist.append(repr(each['attr']))
我想检索,在本例中是父 ID 值,因为选择了孩子。
【问题讨论】:
标签: python xml xml-parsing beautifulsoup