如HTML结构所示,属性是一个私有属性:
// 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或函数。
发布于 2022-07-27 00:44:34
通过访问下面的原始html.Node,我们可以迭代:
for _, node := range e.DOM.Nodes {
fmt.Println(node.Attr)
}https://stackoverflow.com/questions/73131106
复制相似问题