scraping a dynamic and inconsistent dom site <p>topic 2 is trending thread so it returned an extra markup span, that broke my query. How to solve this kind of problem? if I do //span at the end then the others three are out.</p> <pre><code> &lt;li&gt; topic 1 &lt;/li&gt; &lt;li&gt; &lt;span style="color:red"&gt;topic 2&lt;/span&gt; &lt;/li&gt; &lt;li&gt; topic 3 &lt;/li&gt; "poll" &lt;li&gt; topic 4 &lt;/li&gt; </code></pre>