【发布时间】:2020-12-08 13:49:50
【问题描述】:
我有一个 xml 提要,我想从 xml 的这一行获取 te 类别和子类别:
与:
cat = x.find('categories/category/cat/title').text
我只得到第一个(vibo's),还需要(Vibrator Speciaal)
<categories>
<category>
<cat>
<id>1</id>
<title>Vibo's</title> //Need this one
</cat>
<cat>
<id>182</id>
<title>Vibrator Speciaal</title> //and need this one
</cat>
</category>
</categories>
无法按我的意愿工作
【问题讨论】:
-
使用
find_all而不是find- 它给出了所有元素的列表。然后使用for-loop 从所有元素中获取文本。或cat_list[1]从列表中获取第二个元素。
标签: python xml-parsing