62,025
社区成员
发帖
与我相关
我的任务
分享
string content="...."//这个变量值等于园博园首页源代码
HtmlDocument document=new HtmlDocument();
document.LoadHtml(content);
content = string.Empty;
HtmlNodeCollection targetNodeCollection = document.DocumentNode.SelectNodes(@"//div[@class='post_item_foot']");
HtmlNode newHtmlNode;
//这里我想将 xpath= //div[@class='post_item_foot'] 的节点全部替换成下面的标签
if (targetNodeCollection != null && targetNodeCollection.Count>0)
{
foreach (var targetNode in targetNodeCollection)
{
newHtmlNode = HtmlNode.CreateNode("<span>replace words</span>");
targetNode.ParentNode.ReplaceChild(newHtmlNode, targetNode);
}
}
content = document.DocumentNode.OuterHtml;
//问题就是循环替换后,为啥content还是一成不变??问题在哪?