Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

How to find nested element within a class #12

Description

@mytc

I have following node:


<ul class="list clearfix">
 <li> 
     <div>
          <a href=www.example.com/asda">
                     <img src="..sadsada./ssa/3.jpg">
         </a>
      </div>
   </li>
 <li> 
     <div>
          <a href=www.example.comsdsds/sds">
                     <img srr="..sadsada./ssa/2.jpg">
         </a>
      </div>
   </li>
 <li> 
     <div>
          <a href=www.example.com/sdds">
                     <img src="..sadsada./ssa/1.jpg">
         </a>
      </div>
   </li>
</ul>

How do I get all the img src?

matcher := func(n *html.Node) bool {

		if n.DataAtom == atom.A && n.Parent != nil && n.Parent.Parent != nil && n.Parent.Parent.Parent != nil && n.Parent.Parent.Parent.Parent != nil {

			return scrape.Attr(n.Parent.Parent.Parent.Parent, "class") == "list clearfix"
		}
		return false
	}

	images := scrape.FindAll(root, matcher)

Doesn't work for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions