我正在使用此代码(请参阅下文),我希望从中获取值'Day.1'和'Day.2'。
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml("<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.1</div></div></div>" +
"<div class=\"large-10 columns\"><div class=\"box\"><div class=\"table-header\">Day.2</div></div></div>");
var classes = doc.DocumentNode.SelectNodes("//div[@class=\"large-10 columns\"]");
foreach (var item in classes)
{
var str = item.SelectSingleNode("//div[@class=\"box\"]//div[@class=\"table-header\"]");
Output += "Test: " + str.InnerText.Split('.')[1] + "\n";
}
使用此代码,输出为:
Test: 1
Test: 1
为什么变量'str'两次从第一个'table-header'类获取值?
答案 0 :(得分:1)
尝试:
<instance>