首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用colly迭代HTMLElement属性?

用colly迭代HTMLElement属性?
EN

Stack Overflow用户
提问于 2022-07-27 00:39:03
回答 1查看 116关注 0票数 0

如HTML结构所示,属性是一个私有属性:

代码语言:javascript
复制
// HTMLElement is the representation of a HTML tag.
type HTMLElement struct {
    // Name is the name of the tag
    Name       string
    Text       string
    attributes []html.Attribute
    // Request is the request object of the element's HTML document
    Request *Request
    // Response is the Response object of the element's HTML document
    Response *Response
    // DOM is the goquery parsed DOM object of the page. DOM is relative
    // to the current HTMLElement
    DOM *goquery.Selection
    // Index stores the position of the current element within all the elements matched by an OnHTML callback
    Index int
}

有一些函数可以用于获取单个属性,但是我如何迭代所有属性呢?似乎没有明显的方法从该结构访问attributes或函数。

EN

回答 1

Stack Overflow用户

发布于 2022-07-27 00:44:34

通过访问下面的原始html.Node,我们可以迭代:

代码语言:javascript
复制
for _, node := range e.DOM.Nodes {
    fmt.Println(node.Attr)
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73131106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档