How to get list of elements by partial class name?

☆樱花仙子☆ 提交于 2019-12-12 03:45:03

问题


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>

The total number of rows is unknown.

Is it possible to get all the elements (rows) that start with the class name row_?


回答1:


"Is it possible to get all the elements (rows) that start with the class name row_?"

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_"));


来源:https://stackoverflow.com/questions/39672291/how-to-get-list-of-elements-by-partial-class-name

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