/// <summary> /// 获取解析后的章节内容。 /// </summary> /// <param name="content">网页内容。</param> /// <param name="pattern">匹配模式。</param> /// <returns>解析后的章节内容。</returns> public string GetBody(string content, PagePatternViewModel pattern) { if (content is null) { throw new ArgumentNullException(nameof(content)); } if (pattern is null) { throw new ArgumentNullException(nameof(pattern)); } var start = content.IndexOf(pattern.Start); var end = content.IndexOf(pattern.Stop); var sb = new StringBuilder(content.Length); var list = Regex.Matches(content[start..end], pattern.Pattern);
public ConfigViewModel() { // <dt>《颤栗高空》正文</dt> // <dd><a href ="545037108.html">第1章 这也太高了吧?</a></dd> // ... // </dl> _table = new PagePatternViewModel { Start = "正文</dt>", Stop = "</dl>", Pattern = "<a href =\"([^\"]+?)\">([^<]+?)</a>" }; // <div id="content"><br /><br /> “咦?”<br /><br /> // ... // <script>chaptererror();</script> _chapter = new PagePatternViewModel { Start = "<div id=\"content\"><br /><br />", Stop = "<script>chaptererror();</script>", Pattern = ">(?: )*([^<]+?)<" }; }