这段代码给我一个奇怪的例外。 Node "<span class="OrganisationOut"></span>" was not found in the collection
但是当我检查span的外部HTML时,它的<span class="OrganisationOut">National Cheng Kung University</span>
。为什么它尝试删除不同的跨度?删除孩子抛出异常
doc = web.Load(urlTeams);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//tr[contains(@id,'Cell')]"))
{
HtmlNode span = node.SelectSingleNode(".//span");
lbResults2.Items.Add(span.InnerText);
lbResults.Items.Add(node.RemoveChild(span).InnerText.Trim());
}
不要在循环中做多余的DOM选择。 – 2013-03-03 17:29:38
你的意思是'HtmlNode span = node.SelectSingleNode(“.// span”);'部分? – a1204773 2013-03-03 17:30:27
http://stackoverflow.com/questions/8269590/removechild-node-was-not-found-cant-work-it-out看到这个 – 2013-03-03 17:31:16