Git Product home page Git Product logo

Comments (9)

jmonster avatar jmonster commented on May 20, 2024 2

Do you plan to implement this? What about selectors like 'ul > li' to grab immediate children?

from cheerio.

matthewmueller avatar matthewmueller commented on May 20, 2024

I took a look at this earlier - this should be addressed in cheerio-soupselect. I'm hoping to close this bug this weekend.

Here's where the discussion will be: matthewmueller/cheerio-soupselect#7

from cheerio.

siddMahen avatar siddMahen commented on May 20, 2024

I'm not understanding the feature/bug here. I thought that .children() was supposed to return only the immediate descendants (see here). Could you perhaps provide a code example?

Currently it seems as thought:

var cheerio = require("cheerio"),
    $ = cheerio.load('<p><h1></h1><div><anotherd></anotherd></div></p>');

console.log($("p").children());

Returns the appropriate result:

{ '0': 
   { type: 'tag',
     name: 'h1',
     attribs: {},
     parent: 
      { type: 'tag',
        name: 'p',
        children: [Object],
        attribs: {},
        parent: [Object],
        prev: null,
        next: null },
     prev: null,
     next: 
      { type: 'tag',
        name: 'div',
        children: [Object],
        attribs: {},
        parent: [Object],
        prev: [Circular],
        next: null },
     children: [] },
  '1': 
   { type: 'tag',
     name: 'div',
     children: [ [Object] ],
     attribs: {},
     parent: 
      { type: 'tag',
        name: 'p',
        children: [Object],
        attribs: {},
        parent: [Object],
        prev: null,
        next: null },
     prev: 
      { type: 'tag',
        name: 'h1',
        attribs: {},
        parent: [Object],
        prev: null,
        next: [Circular],
        children: [] },
     next: null },
  length: 2 }

from cheerio.

matthewmueller avatar matthewmueller commented on May 20, 2024

It's the selector that looks through the children when it shouldn't. Try:

var $ = cheerio.load('<html><body><h2 class = "header">Header</h2></body></html>')
$('html').children('.header');

I think this is best managed by adding a depth parameter in cheerio-soupselect. Anything else seems like a hack in the .find() function.

from cheerio.

siddMahen avatar siddMahen commented on May 20, 2024

Ahhh, I see the problem.

from cheerio.

jmonster avatar jmonster commented on May 20, 2024

high fives for whoever implements depth + more css3-style selectors ("ul > li")

from cheerio.

matthewmueller avatar matthewmueller commented on May 20, 2024

:-) it's on my todo list but unfortunately my todo list is very long :-/

from cheerio.

fb55 avatar fb55 commented on May 20, 2024

You should be able to use Array.prototype.filter with the method you get from CSSselect as the only argument. (That should also be the most performant way.)

from cheerio.

jugglinmike avatar jugglinmike commented on May 20, 2024

This was indirectly resolved by commit 0464dd8, and an regression test was added in commit 024ac31.

from cheerio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.