Kibi Brat Kibi Brat - 2 months ago 4
HTML Question

Remove HTML tags that contain attribute with given string

I have this HTML code:

<li class="purple">Sky</li>
<li class="purple">Earth</li>
<li class="green">Grass</li>
<li class="purple">Sun</li>

I want to remove all
tags with the attribute

I haven't found any code similar to this online, so I don't have any idea how to do it.


I've found this code. It finds tags with a given attribute value, but I don't know how could I modify it to remove element.

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("li")
If Element.GetAttribute("class") = "green" Then
'What to do
End If


This seems to work:

Dim old = WebBrowser1.Document
    For Each Element As HtmlElement In old.GetElementsByTagName("li")
        If Element.OuterHtml.Contains("green") Then
            Element.OuterHtml = ""
        End If
WebBrowser1.DocumentText = old.Body.InnerHtml