擅长:python、mysql、java
<p>您可以使用以下命令对返回值进行粒度控制。</p>
<pre><code>for element in doc.findall('item'): # Get the items out.
# Iterate thought the list of items(They are in element objects)
print 'Item' # Yey print stuff out!
print 'Name: ', element.find('name').text
print 'Price:', element.find('price').text
</code></pre>
<p>其输出如下:</p>
<pre><code>Item
Name: Blah
Price: 1234
Item
Name: Something
Price: 2345
</code></pre>
<p>代码首先获取所有item元素。然后执行查找以获取价格、名称和打印结果。
此代码确保您总是先打印姓名,然后打印价格。</p>