如何通过部分类名获取元素列表? [英] How to get list of elements by partial class name?
本文介绍了如何通过部分类名获取元素列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个HTML文档,其中有一个表,其中的多行定义为:
I have an HTML document in which there is a table with multiple rows defined as:
<tr class="row_1"></tr>
<tr class="row_2"></tr>
...
<tr class="row_10"></tr>
总行数未知.
是否可以获得以类名row_
开头的所有元素(行)?
Is it possible to get all the elements (rows) that start with the class name row_
?
推荐答案
是否可以获取所有以类名称
row_?
开头的元素(行)"
"Is it possible to get all the elements (rows) that start with the class name
row_?
"
当然可以.使用HAP时,您可以 使用 XPath或LINQ 来表达您的查询:
Sure, it is possible. You can either use XPath or LINQ to express your query when using HAP :
HtmlDocument doc;
....
....
var resultXPath = doc.DocumentNode
.SelectNodes("//tr[starts-with(@class, 'row_')]");
var resultLINQ = doc.DocumentNode
.Descendants("tr")
.Where(o => o.GetAttributeValue("class","").StartsWith("row_"));
这篇关于如何通过部分类名获取元素列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文