解析 HTML 页面并在 Golang 中使用 CSS 选择器获取值

huangapple go评论65阅读模式
英文:

Parse html page and get value using css selector in golang

问题

我想解析HTML中特定div的值。例如,我有一个类名为"funcname"的div,我能在golang中解析这个div的值吗?

英文:

I want to parse value of particular div of HTML.Eg.I have class like "funcname" so can i parse value at this div in golang?

答案1

得分: 14

你可以使用 github.com/PuerkitoBio/goquery 包。如果你熟悉 jQuery 选择器,那对你来说不会有问题。

doc, err := goquery.NewDocument(contents)
// 处理错误
doc.Find(".funcname")
英文:

You can use the github.com/PuerkitoBio/goquery package. If you're familar with jQuery selectors, it won't be a problem for you.

doc, err := goquery.NewDocument(contents)
// handle err
doc.Find(".funcname")

huangapple
  • 本文由 发表于 2015年1月17日 19:00:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/27998747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定