colly 抓取页面乱码问题

glqEason · · 1584 次点击
更多评论
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