【发布时间】:2015-10-19 14:19:40
【问题描述】:
<instance id="activate.v.bnc.00024693" docsrc="BNC">
<answer instance="activate.v.bnc.00024693" senseid="38201"/>
<context>
Do you know what it is , and where I can get one ? We suspect you had seen the Terrex Autospade , which is made by Wolf Tools . It is quite a hefty spade , with bicycle - type handlebars and a sprung lever at the rear , which you step on to <head>activate</head> it . Used correctly , you should n't have to bend your back during general digging , although it wo n't lift out the soil and put in a barrow if you need to move it ! If gardening tends to give you backache , remember to take plenty of rest periods during the day , and never try to lift more than you can easily cope with .
</context>
</instance>
我想提取里面的所有文本。这是我目前拥有的。 stuff.text 只打印<head></head> 之前的文本(即你知道吗...踩到),但我不知道如何提取</head> 之后的后半部分(即它。使用...容易...应付。)
import xml.etree.ElementTree as et
tree = et.parse(os.getcwd()+"/../data/train.xml")
instance = tree.getroot()
for stuff in instance:
if(stuff.tag == "answer"):
print "the correct answer is %s" % stuff.get('senseid')
if(stuff.tag == "context"):
print dir(stuff)
print stuff.text
【问题讨论】: