error: Unmatched selector: 's #59

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

Comments

Projects
None yet
2 participants

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.

Owner

matthewmueller commented Jun 1, 2012

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

Owner

matthewmueller commented Jun 1, 2012

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 [].

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.

$('<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. =)

Owner

matthewmueller commented Jun 12, 2012

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?

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.

Owner

matthewmueller commented Jun 12, 2012

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