Java xpath 获取表格中的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2017119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:37:00  来源:igfitidea点击:

xpath to get rows inside a table

javaxpath

提问by mrblah

I have a html table like:

我有一个 html 表,如:

<table ..... class="cars">

<tr class="item-odd">
...
</tr>
<tr class="item-even">
</tr>

</table>

How could I get the table rows using xpath?

如何使用 xpath 获取表格行?

//tr[contains(@class, ???)

can I use OR in there somehow to say item-odd|item-even

我可以在那里使用 OR 以某种方式说 item-odd|item-even

采纳答案by Malcolm Sparks

You can get the rows like this:

你可以得到这样的行:

//table[@class='cars']/tr

To get the item-odd rows, you would do this:

要获取项目奇数行,您可以这样做:

//table[@class='cars']/tr[@class='item-odd']

Yes, you can use or, e.g.:

是的,您可以使用or,例如:

//table[@class='cars']/tr[@class='item-odd' or @class='item-even']

See http://www.w3.org/TR/xpathfor more details.

有关更多详细信息,请参阅http://www.w3.org/TR/xpath