I am scraping a page using node.js (basically), then jQuerify the result in order to access the CSS values for some elements. However, for some reason, .css("something") always returns an empty value. E.g. .text(), however, is working fine. Any hints? Do I need to output the scraped page first before I can access the CSS?
var request = require('request');
var jsdom = require('jsdom');
var req_url = 'URL';
request({uri: req_url}, function(error, response, html){
if(!error && response.statusCode == 200){
var window = jsdom.jsdom(html).createWindow();
jsdom.jQueryify(window, 'http://code.jquery.com/jquery-1.4.2.min.js', function() {
var bg = window.$("#ID").css("color");
console.log(bg);
});
}
});
I think that .css() will only return the inline css of a given element.
Unfortunately what you're trying to do is hard to do without an active browser.
You should look into PhantomJS-- it combines with node.js easily and acts as a headless webkit that you can inject javascript into.