golang编码转换

来源:互联网 发布:三星指纹锁软件 编辑:程序博客网 时间:2024/06/06 19:48
package main/**https://github.com/xushiwei/go-iconvhttps://github.com/djimenez/iconv-gohttps://github.com/sloonz/go-iconv安装包go get gopkg.in/iconv.v1**/import (    "fmt"    "gopkg.in/iconv.v1"    "io/ioutil"    "log"    "net/http")//view-source:http://b.faloo.com/l/0/0/w/8/8/0/1.htmlfunc main() {    aConv, err := iconv.Open("utf-8", "GBK")    if err != nil {        fmt.Println("iconv.Open failed!")        return    }    defer aConv.Close()    resp, err := http.Get("http://b.faloo.com/l/0/0/w/8/8/0/1.html")    if err != nil {        log.Fatal(err)    }    defer resp.Body.Close()    input, err := ioutil.ReadAll(resp.Body)    str := aConv.ConvString(string(input))    fmt.Println(str)}
0 0
原创粉丝点击