본문 바로가기
개발의 정석/언어

[#golang] html 태그 제거(strip tags)

by 발자개발 2020. 3. 30.

 

 

golang으로 html 페이지를 크롤링하다보면 가끔 태그를 제거하고 텍스트만 받고 싶은 경우가 있다. 이럴때는

package main

import (
    "fmt"
    "github.com/grokify/html-strip-tags-go"
)

func main() {
    text := "Hello World!<div>this is in div element.</div>"

    stripped := strip.StripTags(text)

    fmt.Println(text)
    fmt.Println(stripped)
}

를 사용하면 간단하게 해결할 수 있다.

 

 

 

댓글