我有以下情况我需要使用带有c#
的HtmlAgilityPack在几个嵌套的div中提取一些文本<div class = "content">
<div data-type = "container">
<div class = "level1">
<div class = "level2">
<span>some_text</span>
</div>
</div>
</div>
</div>
我需要得到的文字是“some_text”,我已经尝试了一切,但仍然无法理解这一点。
答案 0 :(得分:0)
var doc = new HtmlDocument();
doc.Load("YOUR_HTML_FILENAME.html");
var node = doc.DocumentNode.SelectSingleNode("//span");
string someText = string.Empty;
if (node != null)
someText = node.InnerText; //result >> some_text