Ich möchte den folgenden HTML-Code analysieren.
Was ich momentan habe ist
var node = document.DocumentNode.SelectSingleNode("//div[@class='wrapper']");
Die HTML ist
<div class="wrapper">
<ul>
<li data="334040566050326217">
<span>test1</span>
</li>
<li data="334040566050326447">
<span>test2</span>
</li>
</ul>
Ich muss die Nummer aus den li data
und den Wert zwischen dem span
Tag abrufen. Jede Hilfe wird geschätzt.
So etwas könnte Ihren Bedürfnissen entsprechen.
//Assumes your document is loaded into a variable named 'document'
List<string> dataAttribute = new List<string>(); //This will contain the long # in the data attribute
List<string> spanText = new List<string>(); //This will contain the text between the <span> tags
HtmlNodeCollection nodeCollection = document.DocumentNode.SelectNodes("//div[@class='wrapper']//li");
foreach (HtmlNode node in nodeCollection)
{
dataAttribute.Add(node.GetAttributeValue("data", "null"));
spanText.Add(node.SelectSingleNode("span").InnerText);
}