Created
October 21, 2010 20:53
-
-
Save Valid/639331 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
require.paths.unshift('lib') | |
require.paths.unshift('/usr/local/lib/node/.npm/html5/active/package/deps/jsdom/lib') | |
var HTML5 = require('html5'), | |
Script = process.binding('evals').Script, | |
sys = require('sys'), | |
fs = require('fs'), | |
jsdom = require('jsdom'), | |
http = require('http'), | |
window = jsdom.createWindow(null, null, { | |
parser: HTML5, | |
document: new jsdom.dom.level1.core.Document() | |
}), | |
uriToParse = 'www.google.com', | |
site = http.createClient(80, uriToParse); | |
request = site.request('GET', '/', { | |
'host': uriToParse | |
}); | |
request.end(); | |
window.document.removeChild(window.document.childNodes[0]); // Clear the stub document that jsdom gives us | |
console.log(window.document.innerHTML); | |
var parser = new HTML5.Parser({ | |
document: window.document | |
}); | |
request.on('response', function (response) { | |
var data = ''; | |
console.log('STATUS: ' + response.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(response.headers)); | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
//console.log('BODY: ' + chunk); | |
data += chunk; | |
}); | |
response.on('end', function (chunk) { | |
//console.log(data); | |
//var inputfile = fs.readFileSync('doc/jquery-example.html'); | |
//inputfile = '<div>hello</div>'; | |
//inputfile = '<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title></head><body><div><p id="testing" class="test">This is a test</p></div></body></html>' | |
//console.log(parser); | |
//console.log(window.document.innerHTML); | |
//parser.parse(inputfile); | |
//console.log(parser); | |
//console.log(window.document.innerHTML); | |
parser.parse(data.replace(/<!.+?>/gi,'')); | |
jsdom.jQueryify(window, '/usr/local/lib/node/.npm/html5/active/package/deps/jquery/dist/jquery.js', function (window, jquery) { | |
Script.runInNewContext('jQuery("div").append("<b>Hi!</b>")', window); | |
sys.puts(Script.runInNewContext('jQuery("#footer").text()', window)); | |
sys.puts(window.document.innerHTML); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment