Problem: potrzeba usunięcia skryptów (tagi <script> i ich zawartości) ze strony html
obecnie mój kod wygląda tak:
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
HtmlWeb web = new HtmlWeb();
var html =
@"<TD class=texte width=""50%"">
<DIV align=right>Name :<B> </B></DIV>
<script>to jest skrypt1</script>
</TD>
<TD width=""50%"">
<INPUT class=box value=John maxLength=16 size=16 name=user_name>
<INPUT class=box value=Tony maxLength=16 size=16 name=user_name>
<INPUT class=box value=Jams maxLength=16 size=16 name=user_name><script>to jest skrypt2</script>
</TD>
<TR vAlign=center>";
htmlDoc.LoadHtml(html);
Console.WriteLine("Przed");
Console.WriteLine(htmlDoc.Text);
htmlDoc = RemoveScripts(htmlDoc);
Console.WriteLine("");
Console.WriteLine("PO");
Console.WriteLine(htmlDoc.Text);
Console.ReadKey();
public static HtmlAgilityPack.HtmlDocument RemoveScripts(HtmlAgilityPack.HtmlDocument webDocument)
{
// Get all Nodes: script
HtmlAgilityPack.HtmlNodeCollection Nodes = webDocument.DocumentNode.SelectNodes("//script");
// Make sure not Null:
if (Nodes == null)
{
Console.WriteLine("brak scripts");
return webDocument;
}
// Remove all Nodes:
foreach (HtmlNode node in Nodes)
{
Console.WriteLine("są scripts");
node.Remove();
}
return webDocument;
}
i niestety kod początkowy i niby po usunięciu tagów script wygląda identycznie.
nie wiem dlaczego kod nie działa bo na necie ludzie opisują identyczne problemy i mają identyczny kod (zresztą swój kod opierałem też na artykule który opisywał taki problem), ale niestety u mnie to nie działa.
Jakieś porady? z góry dzięki
zrzut z działania programu tutaj: https://github.com/MyTempCode/temp/blob/main/temp.png