<div dir="ltr">hello,<br><br>I have a document with a format like this:<br>&lt;doc&gt;text1&lt;b&gt;text2&lt;/b&gt;text3&lt;b&gt;text4&lt;/b&gt;text5&lt;/doc&gt;<br><br>I want to extract &#39;text1text3text5&#39; from &lt;doc&gt; but the text attribute returns just &#39;text1&#39;. Here is an example:<br>
<br>from lxml import html<br>doc = html.fromstring(&#39;&lt;doc&gt;text1&lt;b&gt;text2&lt;/b&gt;text3&lt;b&gt;text4&lt;/b&gt;text5&lt;/doc&gt;&#39;)<br>print doc.text # &#39;text1&#39;<br>print doc.tail # &#39;&#39;<br>print doc.text_content() # &#39;text1text2text3text4text5&#39;<br>
<br>for child in doc:<br>&nbsp;&nbsp;&nbsp; child.drop_tree()<br>print doc.text # &#39;text1text3text5&#39;<br><br><br>From the example you can see I can get what I want by first dropping the subelements. <br>Is there a better way to access this text?<br>
<br>regards,<br>Richard<br></div>