如何根据 div id 子串 html 字符串

How to substring html string based on div id

如果我有一个 html 格式的字符串,如下所示:

<p style="text-align:center">&nbsp;</p>
<p style="text-align:center">&nbsp;</p>
<p style="text-align:center"><strong>To The &lrm;<span>Embassy of The United Kingdom</span>&rlm;</strong></p>
<p>The ORG- certifies that &lrm;<strong><span>Mrs.</span></strong>&rlm;&lrm;<strong>&nbsp;</strong>&rlm;&lrm;<strong><span>Matilda Johan</span></strong>&rlm;,</p>
<p>has been&lrm;&rlm;&lrm;&rlm; working since&nbsp;<strong><span>01/10/2003</span></strong>&rlm; until present.</p>
<p>&lrm;<span>Presently, she is working as</span>&rlm;&lrm;&rlm;&lrm;&nbsp; a / an &lrm;<strong><span>JOB TITLE NOT DEFINED</span></strong>&rlm; at&nbsp;<strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>&rlm;-&lrm;​​​​​​​&rlm;&lrm;​​​&lrm;<strong><span>College of Engineering and Technology </span></strong>&rlm;.</p>
<p><strong>This certificate was issued upon&nbsp;</strong>&lrm;<strong><span>her request</span></strong>&rlm;​​​​​​​&nbsp;<strong>and without any commitment on behalf of the ORG.</strong></p>
<div>
  <div id="dv_sign_en" style="float:left;clear:both;font-style: italic;">...</div>
  <div></div>
</div>

如何仅在 id 以 dv_sign_ 开头的 div 的父 div 之前获取字符串,因此结果将是:

<p style="text-align:center">&nbsp;</p>
<p style="text-align:center">&nbsp;</p>
<p style="text-align:center"><strong>To The &lrm;<span>Embassy of The United Kingdom</span>&rlm;</strong></p>
<p>The ORG- certifies that &lrm;<strong><span>Mrs.</span></strong>&rlm;&lrm;<strong>&nbsp;</strong>&rlm;&lrm;<strong><span>Matilda Johan</span></strong>&rlm;,</p>
<p>has been&lrm;&rlm;&lrm;&rlm; working since&nbsp;<strong><span>01/10/2003</span></strong>&rlm; until present.</p>
<p>&lrm;<span>Presently, she is working as</span>&rlm;&lrm;&rlm;&lrm;&nbsp; a / an &lrm;<strong><span>JOB TITLE NOT DEFINED</span></strong>&rlm; at&nbsp;<strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>&rlm;-&lrm;​​​​​​​&rlm;&lrm;​​​&lrm;<strong><span>College of Engineering and Technology </span></strong>&rlm;.</p>
<p><strong>This certificate was issued upon&nbsp;</strong>&lrm;<strong><span>her request</span></strong>&rlm;​​​​​​​&nbsp;<strong>and without any commitment on behalf of the ORG.</strong></p>
    String html;

    using (StreamReader reader = new StreamReader($@"D:\OneDrive\Dokumentumok\Projects\html.txt")) {
        html = reader.ReadToEnd();
    }

    Int32 index = html.IndexOf("<div id=\"dv_sign_");
    html = html.Substring(0, index);

    index = html.LastIndexOf("<div>");
    html = html.Substring(0, index);