|
@@ -0,0 +1,52 @@
|
|
|
+using HtmlAgilityPack;
|
|
|
+
|
|
|
+namespace GxPress.Common.Tools
|
|
|
+{
|
|
|
+ public static class HtmlAgilityPackHelper
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 完整
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="html"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string GetHmtl(string html)
|
|
|
+ {
|
|
|
+ var document = new HtmlDocument();
|
|
|
+ document.LoadHtml(html);
|
|
|
+ var node = document.DocumentNode.SelectNodes("//body/p");
|
|
|
+ var tittle = document.DocumentNode.SelectNodes("//title");
|
|
|
+ var pContent = $"<h2>{tittle[0].InnerText}</h2>";
|
|
|
+ foreach (var item in node)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(item.InnerHtml))
|
|
|
+ continue;
|
|
|
+ pContent += item.OuterHtml;
|
|
|
+ }
|
|
|
+ return pContent;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 一部分
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="html"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string GetHmtlContent(string html)
|
|
|
+ {
|
|
|
+ var pContent = string.Empty;
|
|
|
+ var document = new HtmlDocument();
|
|
|
+ document.LoadHtml(html);
|
|
|
+ var node = document.DocumentNode.SelectNodes("//body/p");
|
|
|
+ var tittle = document.DocumentNode.SelectNodes("//title");
|
|
|
+ pContent = $"<h2>{tittle[0].InnerText}</h2>";
|
|
|
+ foreach (var item in node)
|
|
|
+ {
|
|
|
+ if (pContent.Length > 100)
|
|
|
+ break;
|
|
|
+ if (string.IsNullOrWhiteSpace(item.InnerHtml))
|
|
|
+ continue;
|
|
|
+ //pContent += item.InnerHtml.ToString()
|
|
|
+ pContent += item.OuterHtml;
|
|
|
+ }
|
|
|
+ return pContent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|