You can with great caution, which you probably shouldn't, if you have one too.
Take the following HTML:
<div> <p> Here is a paragraph <p> Here is another, is it inside the first, who knows? </div>
Now most HTML parsers will agree that this means the following:
<div> <p> Here is a paragraph </p> <p> And another, is it inside the first, who knows? </p> </div>
Now XPath /div/p[2] should return "And another..." , however, it can be equally interpreted as:
<div> <p> Here is a paragraph <p> And another, is it inside the first, who knows? </p> </p> </div>
Where /div/p[2] returns nothing, and XPath /div/p/p returns "And another..." .
HTML is not XML and does not need a good education, so using XML technologies with HTML can lead to idiosyncrasies. So for now, you acknowledge that you should be fine.
user764357
source share