title: Performant parsing of HTML pages with Node.js and XPath
body: <p>I'm into some web scraping with Node.js. I'd like to use XPath as I can generate it semi-automatically with several sorts of GUI. The problem is that I cannot find a way to do this effectively.</p>
  
  <ol>
  <li><code>jsdom</code> is extremely slow. It's parsing 500KiB file in a minute or so with full CPU load and a heavy memory footprint.</li>
  <li>Popular libraries for HTML parsing (e.g. <code>cheerio</code>) neither support XPath, nor expose W3C-compliant DOM.</li>
  <li>Effective HTML parsing is, obviously, implemented in WebKit, so using <code>phantom</code> or <code>casper</code> would be an option, but those require to be running in a special way, not just <code>node &lt;script&gt;</code>. I cannot rely on the risk implied by this change. For example, it's much more difficult to find how to run <code>node-inspector</code> with <code>phantom</code>.</li>
  <li><code>Spooky</code> is an option, but it's <a href="https://github.com/WaterfallEngineering/SpookyJS/issues/71">buggy enough</a>, so that it didn't run at all on my machine.</li>
  </ol>
  
  <p>What's the right way to parse an HTML page with XPath then?</p>