擅长:python、mysql、java
<p>使用<code>lxml</code>可以首先找到<code><b></code>元素,得到<code>tail</code>并将其与以下同级元素组合以生成所需的结果,例如:</p>
<pre><code>from lxml import etree as ET
raw = '''your XML string here'''
root = ET.fromstring(raw)
b = root.xpath("//benefit/div/p/b")[0]
result = b.tail + ''.join(ET.tostring(node) for node in b.xpath("following-sibling::*"))
print result
</code></pre>
<p><strong>输出:</strong></p>
^{pr2}$
<p>或者,如果您想简单地获取<code><p></code>的全部内容,包括其中的标记,那么您可以执行<a href="https://stackoverflow.com/a/29888556/2998271">this way</a>(这个方法可以使用<code>lxml</code>或{<cd6>}:</p>
<pre><code>p = root.find(".//benefit/div/p")
result = p.text + ''.join(ET.tostring(node) for node in p)
</code></pre>
<p><strong>输出:</strong></p>
<pre><code><b>Benefit:</b> Using senses such as acute hearing and sensitivity to vibrations, you detect the location of opponents who are no more than 5 feet away from you. <i>Invisibility</i> and <i>darkness</i> are irrelevant, though it you discern incorporeal beings.
</code></pre>