Is it more reliable to rely on index of occurrence or keywords when parsing websites?
<p>Just started using XPath, I'm parsing a website with lxml.</p>

<p>Is it preferable to do: </p>

<pre><code>number_I_want = parsed_body.xpath('.//b')[6].text 
#or
number_I_want = parsed_body.xpath('.//span[@class="class_name"]')[0].text
</code></pre>

<p>I'd rather find this out now, rather than much further down the line. Actually I couldn't get something like the second expression to work for my particular case. </p>

<p>But essentially, the question: is it better to rely on <code>class</code> names (or other keywords) or indices of occurrence (such as 7th occurrence of bolded text)?</p>

<p>I'd say that it is generally better to rely on <code>id</code> attributes, or <code>class</code> by default, than on the number and order of appearance of specific tags.
That is more resilient to change in the page content.</p>

python xpath lxml