I need to extract pairs of nodes from html code (either HtmlDocument or List of HtmlNodes).
The problem is that I need to select a node (from a list or HtmlDocument, it doesnβt matter what I choose the best solution), which has a class attribute, but no value at all (see the pictures).
Another (better solution, I think) would be to select "node and its immediate next-sibling :: li [1] (link # 2) and its probably what I will do for this part of my program. Link # 2, it seems helps a little, but I donβt know how to use it in such a way as "get all nodes and their first next".
Id like 2 things: - A bit of code to get "one node by class And its first next node", I did not use XPathes (or w / e its callable), but I did not use it - If possible, a way to get "node that has a class attribute but NO VALUE "
The thing is, I have to choose an HtmlNode with the "zero gravity" class later, and Im looking for a way to do this. The idea (if not yet clear enough) would be something like this:
var r = htmlDoc.DocumentNode.Descendants("li").Where(d => d.Attributes["class"].Value.Equals(NULL)); //Iβm not sure about the [enter image description here][1].Value.Equals() ^^β
Links: - How to get the following 2 nodes in HTML + HTMLAgilitypack
But I have never used this before (I could use this to select "node and its immediate next (not going to use this, too creepy)
:
,
2 :
Update
,
<li class>
.
, ( , , , ^^, ), "" , node . :
<li class="A">...</> = > <li class="B">...</> = > <li class="A">...</> = > <li class="B">...</> = >
, A/class B ( , a#, A Content, , B).
tl; dr: - public List<Pair> ExtractPairs(HtmlAgilityPack.HtmlDocument htmlDoc){
List<Pair> pairs = new List<>();
foreach (HtmlNode node in htmlDoc.DocumentNode.SelectNodes("//li[@class='A']")) {
Pair pair = new Pair(node,node
( <li class="B">) );
pairs.add(pair);
}
return pairs;
}