我试图找到一个特定的标签的nextSibling的innerText,但是当我试图解析其中包含空格或新行的HTML字符串我不能得到正确的值
这里是我的代码:
private string getTableTdValue()
{
/*If I strip all white space between tag I get proper results
string myHtml =
"<td align='right' width='186'>Text1</td><td align='center' width='51'>Here the result I want to get</td><td width='186'>Text2</td>";*/
string myHtml =
@"
<td align='right' width='186'>Text1</td>
<td align='center' width='51'>Here the result I want to get</td>
<td width='186'>Text2</td>";
HtmlDocument doc = new HtmlDocument();
HtmlNodeCollection cols = doc.DocumentNode.SelectNodes("//td[@width='186']");
var tdValue = string.Empty;
foreach (HtmlNode col in cols)
{
if (col.InnerText == "Text1")
{
tdValue = col.NextSibling.InnerText;
}
}
return tdValue;
}
我能得到nextSibling值需要内部消除去除标签之间的所有空格?