colly 抓取页面乱码问题

glqEason · · 1634 次点击
glqEason
coding
我折腾半天 import "github.com/axgle/mahonia" //src为要转换的字符串 func coverGBKToUTF8(src string) string { return mahonia.NewDecoder("gbk").ConvertString(src) }
#4
更多评论
str = ConvertToString(str, "gbk", "utf-8")
#1
go get github.com/axgle/mahonia func ConvertToString(src string, srcCode string, tagCode string) string { srcCoder := mahonia.NewDecoder(srcCode) srcResult := srcCoder.ConvertString(src) tagCoder := mahonia.NewDecoder(tagCode) _, cdata, _ := tagCoder.Translate([]byte(srcResult), true) result := string(cdata) return result }
#2