如果我有一個像這樣的 html 格式的字串:
<p style="text-align:center"> </p>
<p style="text-align:center"> </p>
<p style="text-align:center"><strong>To The ‎<span>Embassy of The United Kingdom</span>‏</strong></p>
<p>The ORG- certifies that ‎<strong><span>Mrs.</span></strong>‏‎<strong> </strong>‏‎<strong><span>Matilda Johan</span></strong>‏,</p>
<p>has been‎‏‎‏ working since <strong><span>01/10/2003</span></strong>‏ until present.</p>
<p>‎<span>Presently, she is working as</span>‏‎‏‎ a / an ‎<strong><span>JOB TITLE NOT DEFINED</span></strong>‏ at <strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>‏-‎???????‏‎???‎<strong><span>College of Engineering and Technology </span></strong>‏.</p>
<p><strong>This certificate was issued upon </strong>‎<strong><span>her request</span></strong>‏??????? <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 開頭的 div 的父 div 之前獲取字串dv_sign_,結果將是:
<p style="text-align:center"> </p>
<p style="text-align:center"> </p>
<p style="text-align:center"><strong>To The ‎<span>Embassy of The United Kingdom</span>‏</strong></p>
<p>The ORG- certifies that ‎<strong><span>Mrs.</span></strong>‏‎<strong> </strong>‏‎<strong><span>Matilda Johan</span></strong>‏,</p>
<p>has been‎‏‎‏ working since <strong><span>01/10/2003</span></strong>‏ until present.</p>
<p>‎<span>Presently, she is working as</span>‏‎‏‎ a / an ‎<strong><span>JOB TITLE NOT DEFINED</span></strong>‏ at <strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>‏-‎???????‏‎???‎<strong><span>College of Engineering and Technology </span></strong>‏.</p>
<p><strong>This certificate was issued upon </strong>‎<strong><span>her request</span></strong>‏??????? <strong>and without any commitment on behalf of the ORG.</strong></p>
uj5u.com熱心網友回復:
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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/393389.html
標籤:C# html 网站 细绳 html-agility-pack
