Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find nested element within a class #12

Open
mytc opened this issue Dec 16, 2017 · 0 comments
Open

How to find nested element within a class #12

mytc opened this issue Dec 16, 2017 · 0 comments

Comments

@mytc
Copy link

mytc commented Dec 16, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant