J'ai de la difficulté à supprimer un div avec un identifiant particulier, et ses enfants utilisent le pack HTML Agility. Je suis sûr que je manque juste une option de configuration, mais c'est vendredi et je me bats.html agility pack supprimer les enfants
Les pistes HTML simplifié:
<html><head></head><body><div id='wrapper'><div id='functionBar'><div id='search'></div></div></div></body></html>
C'est aussi loin que j'ai. L'erreur lancée par le pack d'agilité montre qu'il ne peut pas trouver une structure div:
<div id='functionBar'></div>
Voici le code à ce jour (extrait de Stackoverflow ....)
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
// There are various options, set as needed
//htmlDoc.OptionFixNestedTags = true;
// filePath is a path to a file containing the html
htmlDoc.LoadHtml(Html);
string output = string.Empty;
// ParseErrors is an ArrayList containing any errors from the Load statement
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count > 0)
{
// Handle any parse errors as required
}
else
{
if (htmlDoc.DocumentNode != null)
{
HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
if (bodyNode != null)
{
HtmlAgilityPack.HtmlNode functionBarNode = bodyNode.SelectSingleNode ("//div[@id='functionBar']");
bodyNode.RemoveChild(functionBarNode,false);
output = bodyNode.InnerHtml;
}
}
}
génie - merci! –