Comments (9)
Do you plan to implement this? What about selectors like 'ul > li' to grab immediate children?
from cheerio.
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.
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.
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.
Ahhh, I see the problem.
from cheerio.
high fives for whoever implements depth + more css3-style selectors ("ul > li")
from cheerio.
:-) it's on my todo list but unfortunately my todo list is very long :-/
from cheerio.
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.
This was indirectly resolved by commit 0464dd8, and an regression test was added in commit 024ac31.
from cheerio.
Related Issues (20)
- Can't start telegram bot HOT 3
- issue with custom tags defined in head HOT 2
- Incorrect code example in intro documation
- Multiple html tags are deleted HOT 2
- TypeError: cheerio.fromURL is not a function HOT 6
- How to "replaceWith" on plain text, which is not a DOM Elements? HOT 5
- Unsafe legacy renegotiation disabled
- text() method merges text parts HOT 3
- Bug: Crawler reached the maxRequestsPerCrawl limit of 1 requests and will shut down soon HOT 1
- Bug: XML tags with mixed case, when using lowerCaseTags: true, selectors will be lowercased before comparing with the xml tag name
- exporting function from battiers
- Error with nextjs 14 HOT 1
- Cherrio is unable to retrieve content with property of og in the meta tag HOT 3
- If the page is SPA (such as Vue), can't I use Cheerio to retrieve the content of the website that has been fully loaded HOT 1
- whitespace normalization removes NBSP chars in xmlMode HOT 1
- Can´t select elements based on their position in the document HOT 2
- Live Editor Result Panel Blank
- how to add defer to script tag HOT 1
- Weird behaviour with HTML entities within XML content
- Behaving exceptionally in template syntax containing curly braces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cheerio.