I am new to nodejs. I want to use jsdom to parse some web pages that may contain script code inside. But I got an error indicating that the function or variable is not defined. Can someone give some guidance on this.
my code
var jsdom = require('jsdom');
jsdom.env({
html: 'http://10.200.0.10:8080/test/a.html',
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
],
done: function(errors, window) {
var $ = window.$;
window.onload();
console.log(window.a);
}
});
and html page here
<html>
<head>
<script>
var a = 0;
function loads(){
a=1000;
}
</script>
</head>
<body onload='loads()'>
</body>
</html>
and got an error message below
dfddddfdf
undefined:1: ReferenceError: loads is not defined
loads()
^
ReferenceError: loads is not defined
at unknown source
at /root/node_modules/jsdom/node_modules/contextify/lib/contextify.js:10:24
at /root/node_modules/jsdom/lib/jsdom/level1/core.js:1024:50
at /root/testnode.js:18:12
at Array.0 (/root/node_modules/jsdom/lib/jsdom.js:199:39)
at EventEmitter._tickCallback (node.js:192:40)
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: loads is not defined
at unknown source
at /root/node_modules/jsdom/node_modules/contextify/lib/contextify.js:10:24
at /root/node_modules/jsdom/lib/jsdom/level1/core.js:1024:50
at /root/testnode.js:18:12
at Array.0 (/root/node_modules/jsdom/lib/jsdom.js:199:39)
at EventEmitter._tickCallback (node.js:192:40)
It is reported that the download function is not defined, but has actually been announced on the web page.
Can someone give some suggestions or just tell me that jsdom cannot handle scripts embedded in the page.
source
share