需要 Body 标签内的数据,但不需要任何其他标签

Need data inside the Body tag, but no any other tag

您好,我有 html 格式的简历, 我正在使用 StreamReader 读取文件,并且正在使用以下方法删除标签。

using (StreamReader sr = new StreamReader("\Myfile.html"))
                {
                    String line = sr.ReadToEnd();
                    string jj = Regex.Replace(line, "<.*?>", String.Empty);
    }

它的工作该死的酷

但是根据我的要求,我只需要 body 标签内的数据。 但是没有 body 标签,里面也没有标签。

不要使用 Regex 进行 HTML/XML 解析。使用 Html/Xml 解析器。这里很好地解释了为什么你不应该使用它。

RegEx match open tags except XHTML self-contained tags

Can you provide some examples of why it is hard to parse XML and HTML with a regex?

您可以使用 HTML 敏捷包

在 Html 文档中加载字符串

这里是如何操作的小例子:

public string ReplacePElement() 
{
    HtmlDocument doc = new HtmlDocument();
    doc.Load(htmlFile);

    foreach(HtmlNode p in doc.DocumentNode.SelectNodes("body"))
    {

    }

    return doc.DocumentNode.OuterHtml;
}