问题
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