使用 Go Colly 获取属性值
在“html”中使用 c.OnHTML 时,如何获取 #id-card-1 ID 内的 href 属性的值?
c.OnHTML("html", func(e *colly.HTMLElement) {
...
linkStr := "#id-card-1[href]" //???
log.Print(e.Attr(linkStr))
...}
这是页面中的 HTML 片段:
<a href="/some-link-here" target="_blank" id="id-card-1" class="card card--featured" data-item-card="11042036">
When working with c.OnHTML in "html", how can I get the value of the href attribute inside the #id-card-1 ID?
c.OnHTML("html", func(e *colly.HTMLElement) {
...
linkStr := "#id-card-1[href]" //???
log.Print(e.Attr(linkStr))
...}
This is the piece of HTML in the page:
<a href="/some-link-here" target="_blank" id="id-card-1" class="card card--featured" data-item-card="11042036">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ChildAttr
函数可以用于此目的。https://pkg.go.dev/github.com/gocolly/ colly#HTMLElement.ChildAttr
The
ChildAttr
function can use for this purpose.https://pkg.go.dev/github.com/gocolly/colly#HTMLElement.ChildAttr