Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

初学go 爬虫抓取数据,定义一个函数,把数据作为参数,在函数转成了数字,如下图和代码

问题

go 爬虫抓取数据,定义一个函数,把数据作为参数,在函数转成了数字,想拿到图中蓝色的内容

代码

func ParserCityList(content []byte) {
    fmt.Printf("%s
", content)
    fmt.Println("content", content)
    const reg = "<a href='(http://www.zhenai.com/zhenghun/[a-zA-Z0-9]+)'[^>]*>([^<]+)</a>"
    re := regexp.MustCompile(reg)
    matches := re.FindAllSubmatch(content, -1)
    fmt.Println("content", content)
    fmt.Println("re", re)
    fmt.Println("matches", matches)
    for _, m := range matches {
        fmt.Printf("City:%s, URL:%s
", m[2], m[1])
    }
}

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你打印的是字节切片 []byte ,不是数字,如果想看字符串这样就好

fmt.Println("content",string(content))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...