1 | package main |
2 | |
3 | import ( |
4 | "strings" |
5 | |
6 | "golang.org/x/net/html" |
7 | ) |
8 | |
9 | func extractText(input string) string { |
10 | buf := strings.NewReader(input) |
11 | z := html.NewTokenizer(buf) |
12 | content := "" |
13 | loop: |
14 | for { |
15 | tt := z.Next() |
16 | switch tt { |
17 | case html.ErrorToken: |
18 | break loop |
19 | case html.TextToken: |
20 | content = content + string(z.Text()) |
21 | } |
22 | } |
23 | return content |
24 | } |