Reputation: 5853
This is a snippet of what I'm trying to do at the moment:
var sys = require("sys"),
request = require("request"),
$ = require("jquery"),
uri = 'http://' + process.argv[2];
request({uri:uri}, function (error, response, context) {
if (!error && response.statusCode == 200) {
console.log($('body', context).css('background'));
}
})
Obviously, this just returns undefined; is there a way to apply the stylesheets defined in the link elements so that I can query them with jQuery?
Upvotes: 0
Views: 165
Reputation: 46745
As Pointy already pointed out (scnr) this is by no means trivial.
You need to:
Basically you need a browser rendering engine without the actual drawing, that will take a lot of code in JavaScript (50k LOC+ if one's lucky), you need to implement all the CSS versions, check the document type etc.
Right now the best thing one could do is to grab that stuff out of WebKit and bind it with V8 for a Node C extension. A pretty huge job, so unless you're willing to start this on your own, I guess you're out of luck.
Binding the things will take quite some effort, but it will still take way less time then writing the whole thing in JS from scratch (which will be horrible slow, even with the current increase in JavaScript performance).
Upvotes: 3