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

error: Unmatched selector: 's #59

Closed
lookfirst opened this issue Jun 1, 2012 · 7 comments
Closed

error: Unmatched selector: 's #59

lookfirst opened this issue Jun 1, 2012 · 7 comments

Comments

@lookfirst
Copy link

First off, thanks for a brilliant project. I'm using cheerio 0.8.0:

My code looks like this:

$($(cols.get(3)).html())

The html returned from the $(cols.get(3)).html() looks like this:

Kid&#39;s Ride&nbsp;<br/>Foo&nbsp;<br/>&nbsp;<br/><font color="#000000">Permitted</font><br/>Category - D&nbsp;&nbsp;<br/><br/>\n

When I try to wrap that output back into the outer $() so that I can do more selects on it, this is the stack trace I see:

    at parse (node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/node_modules/CSSwhat/index.js:109:11)\n    
    at parse (node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/index.js:646:18)\n    
    at Function.iterate (node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/index.js:687:42)\n    
    at node_modules/cheerio/node_modules/cheerio-select/lib/select.js:13:20    
    at [object Object].find (node_modules/cheerio/lib/api/traversing.js:7:14)
    at [object Object].init (node_modules/cheerio/lib/cheerio.js:67:44)
    at node_modules/cheerio/lib/cheerio.js:11:12
    at fn (node_modules/cheerio/lib/api/utils.js:246:12)

I suspect it has something to do with the entity (') in there as other similar html without the single quote in it parses just fine.

@matthewmueller
Copy link
Member

Hm... I'll look into this. For the time being you should be able to do... $(cols).eq(3).

@matthewmueller
Copy link
Member

Oh I see what's going on... it's thinking that the string is a selector and not an HTML string.. strange.

Edit: jQuery does not even recognize that as an HTML string. It handles the response a bit more gracefully though with [].

@lookfirst
Copy link
Author

Similar problem with this html:

Eastern States Cup #8-fin&nbsp;<br>Downhill&nbsp;

Results in:

Error: Unmatched selector:&nbsp;<br/>Downhill&nbsp;<br/>&nbsp;

While $(cols).eq(3) works, I still need to parse that line of text and grab stuff from it.

@lookfirst
Copy link
Author

$('<div/>').html(cols.eq(3).html().replace(/&nbsp;/g, ' ')).eq(0).children()

I'm no expert, so that is the best I could do. Gross. =)

@matthewmueller
Copy link
Member

Okay, I'll make adjustments so that it does not error out, but just to be clear - jQuery returns [] on $('Eastern States Cup #8-fin&nbsp;<br>Downhill&nbsp;').. this is the behavior your anticipating?

@lookfirst
Copy link
Author

I vote for making it work correctly... which would be to parse it as if it was living inside a <div>. I didn't write this html, someone else did so I'm stuck with junk html. Right now, it sits within a <td> element. I grab the chunk of data from the td and then I want to grab bits from there. I either need to write my own parser or just assume that it is more html. Given that this project is supposed to be lenient to bad html, I think it should give me a set of elements.

@matthewmueller
Copy link
Member

I'm not planning on deviating from how jQuery handles this case. For your use case you could explicitly wrap your input in <div> tags.

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

No branches or pull requests

2 participants