我正在尝试查找特定标签的 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 值吗?