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

Cheerio versions > 0.3.0 fail when trying to get access to selectors nested two or more levels deep. #18

Closed
ccarollo opened this issue Dec 19, 2011 · 5 comments

Comments

@ccarollo
Copy link

Hi Matthew,

First off, really like Cheerio. Great work! Fast and easy to use. We are using it heavily and have been able to develop quickly with it.

However, since 0.3.0 we are no longer able to get to nested divs that are two or more levels deep and render additional data in those elements. Here is an example.

I have template that looks like the following:

https://gist.github.com/1500031

When I try to do something like the following it used to work and now it fails.

template = get('games.html');
$ = gamefly.cheerio.load(template);
$('.ttl').text("Call of Duty");

This appears to fail starting with 0.3.1. Any ideas?

Thanks
Christian

@matthewmueller
Copy link
Member

Thanks @ccarollo for your kind words. I'll look into this problem.

In the meantime could you fix the formatting of this issue? It's making everything a link - I think you need to indent the outermost <div>s 4 spaces to kick in the correct formatting.

@ccarollo
Copy link
Author

I couldn't get the formatting resolved so I went ahead and made a gist. I have update the original issue with the gist url. Hope this helps and thanks for looking into the issue.

@siddMahen
Copy link

This issue is because of a recursion problem in htmlparser2. I've sent a patch which was accepted, but the current release still doesn't have it. If you would like to fix the issue, go to your nearest ./node_modules folder and navigate to htmlparser's ./lib folder. Then change the 18th line of DomUtils.js from:

childs = filterArray(test, childs, limit);

to

childs = filterArray(test, childs, recurse, limit);

Hope this helps.

@matthewmueller
Copy link
Member

@ccarollo Did this get resolved?

@ccarollo
Copy link
Author

Yes this appears to be resolved. It looks as though the bug in HTMLParser2 was the culprit and since @siddMahen's fix was included in version 2.1.2 of HTMLParser2 all is good. Thanks for everyones help.

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

3 participants