How to remove HTML element (select by class) of string by golang?

Viewed 59

The example below:

content := "<p><a href=\"https://github.com/\">https://github.com/</a></p>
<div class=\"extract\">
   <p>hello1</p>
</div>
<div>hello2</div>
<div class=\"extract\"><p>hello3</p></div>"

I want to remove all "div" that has [class="extract"] include of all children elements too.

I want to get below result

content := "<p><a href=\"https://www.i-boss.co.kr/\">https://github.com/</a></p>
<div>hello2</div>"

I try to use regex, but it`s not working

1 Answers

You can use goquery to parse and modify your HTML

Related