C#HTMLAgilityPack HTML到文本-解析错误
我需要使用C#从HTML文件中提取文本。 我试图使用HTMLAgilityPack,但我看到一些解析错误(标记未关闭)。 我使用这两个选项:C#HTMLAgilityPack HTML到文本-解析错误,c#,html-parsing,html-agility-pack,C#,Html Parsing,Html Agility Pack,我需要使用C#从HTML文件中提取文本。 我试图使用HTMLAgilityPack,但我看到一些解析错误(标记未关闭)。 我使用这两个选项: htmlDoc.OptionFixNestedTags = true; htmlDoc.OptionAutoCloseOnEnd = true; 是否有任何“全部修复”类型选项。我不在乎这些错误,我只想要内容或关闭。也许这是解决办法,但一旦我不得不从HTML中提取文本,我就使用正则表达式: result = Regex.R
htmlDoc.OptionFixNestedTags = true;
htmlDoc.OptionAutoCloseOnEnd = true;
是否有任何“全部修复”类型选项。我不在乎这些错误,我只想要内容或关闭。也许这是解决办法,但一旦我不得不从HTML中提取文本,我就使用正则表达式:
result = Regex.Replace(result, @"<(.|\n)*?>", String.Empty);
result = Regex.Replace(result, @"^\n*", String.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\n*$", String.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase);
result = result.Replace("\n", " ");
result=Regex.Replace(result,@“”,String.Empty);
result=Regex.Replace(result,@“^\n*”,String.Empty,RegexOptions.Singleline | RegexOptions.IgnoreCase);
result=Regex.Replace(result,@“\n*$”,String.Empty,RegexOptions.Singleline | RegexOptions.IgnoreCase);
结果=结果。替换(“\n”和“);