Get option from specific start position?

五迷三道 提交于 2019-12-12 19:33:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!