다음 HTML을 구문 분석하고 싶습니다.
현재 내가 가진 것은
var node = document.DocumentNode.SelectSingleNode("//div[@class='wrapper']");
HTML은
<div class="wrapper">
<ul>
<li data="334040566050326217">
<span>test1</span>
</li>
<li data="334040566050326447">
<span>test2</span>
</li>
</ul>
li data
와 span
태그 사이의 값을 span
합니다. 어떤 도움을 주셔서 감사합니다.
이 같은 것이 귀하의 필요에 부합 할 수 있습니다.
//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);
}