Created
July 10, 2010 05:28
-
-
Save lancejpollard/470467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
<head> | |
<title>Parent Page wanting to Parse Children</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<meta name="keywords" content="parent, html, parsing"> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$.get("/path/to/child.html", function(data) { | |
// data looks like this: | |
// <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
// <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
// <head> | |
// <title>Sub Page to Parse</title> | |
// <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"><\/script> | |
// <meta name="keywords" content="parent, html, parsing"> | |
// </head> | |
// <body> | |
// <script type="text/javascript"> | |
// alert("i'm javascript"); | |
// <\/script> | |
// </body> | |
// </html> | |
// want to parse like this: | |
var child_body = $(data).find("body"); | |
$("#place_child_here").append(child_body); | |
}); | |
}); | |
</script> | |
<div id="place_child_here"> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
<head> | |
<title>Parent Page wanting to Parse Children</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<meta name="keywords" content="parent, html, parsing"> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
// data looks like this: | |
var html = "" | |
html += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' | |
html += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' | |
html += ' <head> ' | |
html += ' <title>Sub Page to Parse</title> ' | |
html += ' <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"><\/script>' | |
html += ' <meta name="keywords" content="parent, html, parsing"> ' | |
html += ' </head> ' | |
html += ' <body> ' | |
html += ' <script type="text/javascript"> ' | |
html += ' alert("im javascript"); ' | |
html += ' setTimeout(function() { ' | |
html += ' $("body").css("background-color", "#ffaaaa") ' | |
html += ' }, 400); ' | |
html += ' <\/script> ' | |
html += ' <div id="child_div"></div> ' | |
html += ' </body> ' | |
html += '</html>' | |
// this works fine: | |
// $("#parent_div").append(html); | |
// $("#child_div") | |
// .width(100) | |
// .height(100) | |
// .css("background-color", "yellow") | |
// .append("<p>child text</p>"); | |
// ... 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()); | |
}); | |
</script> | |
<div id="parent_div"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment