0

I need to parse a not-so-well-formed html using cheerio.js in node.js (which is pretty close to jQuery) and run into this problem. The html looks like this:

<table><tbody><tr>
<td class="symbol">XXX
<td class="price"><span id="l">3,310.30</span>
</td><td class="change"><span id="c">+11.94</span> <span id="cp">(0.36%)</span></td><tr>

The browser seems to be capable to handle this case without any problem.

The problem is that the selector $('td.symbol') will not stop at the first <td, because of missing </td> tag, but includes everything below. How to fix it?

newman
  • 6,841
  • 21
  • 79
  • 126
  • 3
    Add the missing sounds like the easiest solution. – Arunas Feb 28 '15 at 03:58
  • 1
    would bet IE doesn't like that markup. Closing `` is also invalid – charlietfl Feb 28 '15 at 04:03
  • 1
    It has nothing to do with jQuery, jQuery will just work on the created dom structure... so it is entirely depending on how the browser is creating the dom structure... though this looks fine - http://jsfiddle.net/arunpjohny/kkrqwshq/1/ – Arun P Johny Feb 28 '15 at 04:20
  • If you noticed, he's not running this in a browser, so whether IE likes it or any other browser creates a DOM around it is immaterial. Nor is this really a jquery question. The OP is running this in cheerio.js in node.js, which is on the server side. – Arunas Feb 28 '15 at 17:32
  • @miliu - you might find this to be enlightening: http://stackoverflow.com/questions/6657216/why-doesnt-node-js-have-a-native-dom – Arunas Feb 28 '15 at 17:35

0 Answers0