title: What is the best way to parse html in google apps script
body: <pre><code>var page = UrlFetchApp.fetch(contestURL);
  var doc = XmlService.parse(page);
  </code></pre>
  
  <p>The above code gives a parse error when used, however if I replace the XmlService class with the deprecated Xml class, with the lenient flag set, it parses the html properly. </p>
  
  <pre><code>var page = UrlFetchApp.fetch(contestURL);
  var doc = Xml.parse(page, true);
  </code></pre>
  
  <p>The problem is mostly caused because of no CDATA in the javascript part of the html and the parser complains with the following error.</p>
  
  <pre><code>The entity name must immediately follow the '&amp;' in the entity reference.
  </code></pre>
  
  <p>Even if I remove all the <code>&lt;script&gt;(.*?)&lt;/script&gt;</code> using regex, it still complains because the <code>&lt;br&gt;</code> tags aren't closed.
  Is there a clean way of parsing html into a DOM tree.</p>