나는 html을 좋아한다 :
<div class="asd"> lalala </br> lalala2 <div> aaaaa </div> </div>
XPath를 사용하지 않고 "lalala \ n lalala2"만 가져와야합니다.
HtmlNode에 대한 확장 메소드를 생성 할 수 있습니다.
public static class HtmlHelper
{
public static string InnerText(this HtmlNode node)
{
var sb = new StringBuilder();
foreach (var x in node.ChildNodes)
{
if (x.NodeType == HtmlNodeType.Text)
sb.Append(x.InnerText);
if (x.NodeType == HtmlNodeType.Element && x.Name == "br")
sb.AppendLine();
}
return sb.ToString();
}
}
그냥 노드를 찾아 node.InnerText ()를 호출하면됩니다.