Cheerio: .CSS() Documentation

Created on 6 Jan 2014  路  3Comments  路  Source: cheeriojs/cheerio

I'm really enjoying Cheerio, but have hit a wall with .CSS() method.

var request = require('request'),
cheerio = require("cheerio");

var arbitraryPage = 'http://www.bonobos.com/slim-red-and-navy-tattersall-oxford-shirt-for-men';

request(arbitraryPage, function(err, resp, html){
$ = cheerio.load(html);
$('.price').css('color'); //UNDEFINED
});

Am I missing something? Do I need to import the css like jsDom?

Most helpful comment

Hello, why can't simple styles be obtained?

url:http://nipponcolors.com/#nadeshiko

image

this will return {}, why?

All 3 comments

@becush Cheerio operates over a DOM-like structure generated through string parsing only. This allows it to be much faster than jsDom at the cost of some fidelity. In this case, because Cheerio does not actually parse and apply CSS, the css method can only return styling that has been applied in-line via the style attribute. If you need to do more advanced CSS scraping, I would recommend using jsDom.

Ok, thanks! I'll pull documentation to update.

Hello, why can't simple styles be obtained?

url:http://nipponcolors.com/#nadeshiko

image

this will return {}, why?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clayrisser picture clayrisser  路  4Comments

chenweiyj picture chenweiyj  路  5Comments

misner picture misner  路  3Comments

bxqgit picture bxqgit  路  3Comments

dandv picture dandv  路  5Comments