go-colly 库能做什么?
go-colly库可以抓取div标签下的所有HTML标签和文本内容吗?如果是这样,怎么办?我可以获取 div 标签下的所有文本。像这样:
c.OnHTML("body .post-topic-main .post-topic-des", func(e *colly.HTMLElement) {
text = strings.TrimSpace(e.Text)
})
但我不知道如何获取div标签下的HTML标签。
Can the go-colly library crawl all HTML tags and text content under a div tag? If so, how? I can get all texts under a div tag. Like this:
c.OnHTML("body .post-topic-main .post-topic-des", func(e *colly.HTMLElement) {
text = strings.TrimSpace(e.Text)
})
But I dont'know how to get HTML tags under the div tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您寻找
innerHTML
,它可以通过DOM
并使用Html
方法 (e.DOM.Html()
)。如果您在已创建的元素下寻找特殊标记,
ForEach
可以用于此目的。第一个参数是选择器,第二个参数是回调函数。回调函数将迭代每个与选择器匹配并且也是e
元素成员的元素。更多信息:https://pkg.go.dev /github.com/gocolly/[电子邮件受保护]#HTMLElement.ForEach
If you looking for
innerHTML
it is accessible byDOM
and usingHtml
method (e.DOM.Html()
).If you looking for a special tag under the founded element,
ForEach
could use for this purpose. The first argument is the selector and the second parameter is the callback function. The callback function will iterate for each element that matches the selector and also is a member of thee
element.More information: https://pkg.go.dev/github.com/gocolly/[email protected]#HTMLElement.ForEach