问题
I've a select like this:
<select class="foo">
<option></option>
<option>item1</option>
<option>item2</option>
</select>
I need to get only the option that have text inside, so I need to skip the first option and get only Item1
and Item2
what I did
var opts = doc.DocumentNode.SelectNodes("//select[@class='foo']//option");
this will return of course 3 options, how can I do this? Thanks.
回答1:
Working xpath:
"//select[@class='foo']//option[string-length( text()) > 0]"
回答2:
This XPath might work faster as there is no calculation needed:
"//select[@class='foo']//option[text()]"
来源:https://stackoverflow.com/questions/47430495/get-option-from-specific-start-position