colly 抓取页面乱码问题

glqEason · · 1634 次点击
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