title: Scrape an HTML Document with jQuery, is it possible?
body: <p>I want to be able to grab an HTML page and parse it using only Javascript, nothing touches the server.</p>
  
  <p>Assuming I can get the html response (solved the cross-domain issues), how can I use jQuery on the complete html document?</p>
  
  <p>Example is like this (<strong><a href="http://gist.github.com/470467" rel="nofollow noreferrer">here is a full gist with a remote example</a></strong>):</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
    &lt;head&gt;
      &lt;title&gt;Parent Page wanting to Parse Children&lt;/title&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;meta name="keywords" content="parent, html, parsing"&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script type="text/javascript"&gt;
        $(document).ready(function() {
          //  data looks like this:
          var html = ""
          html += '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;'
          html += '&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;'
          html += '  &lt;head&gt;                                                        '
          html += '    &lt;title&gt;Sub Page to Parse&lt;/title&gt;                            '
          html += '    &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;\/script&gt;'
          html += '    &lt;meta name="keywords" content="parent, html, parsing"&gt;      '
          html += '  &lt;/head&gt;                                                       '
          html += '  &lt;body&gt;                                                        '
          html += '    &lt;script type="text/javascript"&gt;                             '
          html += '      alert("im javascript");                                   '
          html += '      setTimeout(function() {                                   '
          html += '        $("body").css("background-color", "#ffaaaa")            '
          html += '      }, 400);                                                  '
          html += '    &lt;\/script&gt;                                                  '
          html += '    &lt;div id="child_div"&gt;&lt;/div&gt;                                  '
          html += '  &lt;/body&gt;                                                       '
          html += '&lt;/html&gt;'
  
  // this works fine:
  //        $("#parent_div").append(html);
  //        $("#child_div")
  //          .width(100)
  //          .height(100)
  //          .css("background-color", "yellow")
  //          .append("&lt;p&gt;child text&lt;/p&gt;");
  // ... but that's not what I am trying to do...
  
  // reason being: i don't want to add this sub-html page to the dom...
  // I just want to scrape it for data...
  
  // I want to do this, but I am getting null for every case:
          var meta = $(html).find("meta");
          alert(meta.html());
          var title = $(html).find("title");
          alert(title.html());
  
        });
      &lt;/script&gt;
      &lt;div id="parent_div"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is, <code>var child_body = $(data).find("body");</code> doesn't give me anything.  I'm not sure how I should be going about traversing this complete html document using jQuery.  I have tried to remove the <code>&lt;!DOCTYPE...&gt;</code> tag, but that doesn't do much.</p>
  
  <p>Is something like this possible?</p>
  
  <p>I have been messing around with <a href="http://ejohn.org/apps/htmlparser/" rel="nofollow noreferrer">John Resig's Javascript HTML Parser</a> but that doesn't quite cover it yet.</p>
  
  <p>Is there an XPath javascript library that would be more suitable?</p>