【发布时间】:2018-05-16 07:57:13
【问题描述】:
我正在使用以下代码从具有这种格式的 div 中提取内容:<div id="post-contents"></div>
string findtext2 = @"<div[^>]*\\id=\post-contents\[^>]*>(.*?)</div>";
string myregex2 = txt;
MatchCollection doregex2 = Regex.Matches(myregex2, findtext2);
string matches2 = "";
foreach (Match match2 in doregex2)
{
matches2 = (matches2 + (match2.ToString()));
}
return matches2;
但是我遇到了一些关于 HTML 标签的错误。实际上,该标签还包含一些其他 HTML 标签,如下所示:
<div id="post-contents"><p dir="ltr">HI HI HI</p></div>
请你帮我,我怎样才能得到<p dir="ltr">HI HI HI</p>?
谢谢
【问题讨论】:
-
使用 HtmlAgilityPack。见here。
-
@john 我不知道。你能帮忙吗?
-
这里,检查一下:How to use HTML Agility pack。
-
查看here 了解您想要做的事情。它是一个 td,而不是一个 div,但概念完全一样。