I'm trying to scrape all the css rules on an html page. This question has been asked elsewhere but I have not found a solution for sites like stackoverflow. If you paste in the console:
for (var p in document.styleSheets) {
console.log(document.styleSheets[p])
}
you will notice that some of the cssRules
are null (at least in chrome).
CSSStyleSheet {ownerRule: null, cssRules: null, rules: null, type: "text/css", href: "http://cdn.sstatic.net/stackoverflow/all.css?v=284b207e2cf7"…}
CSSStyleSheet {ownerRule: null, cssRules: CSSRuleList, rules: CSSRuleList, type: "text/css", href: null…}
CSSStyleSheet {ownerRule: null, cssRules: CSSRuleList, rules: CSSRuleList, type: "text/css", href: "http://static.adzerk.net/Extensions/adFeedback.css"…}
CSSStyleSheet {ownerRule: null, cssRules: null, rules: null, type: "text/css", href: "http://cdn.sstatic.net/clc/styles/jobs.min.css?v=8228069a845b"…}3
Simply navigating to http://cdn.sstatic.net/stackoverflow/all.css?v=284b207e2cf7 will produce the minified css, however.
Is there any way of programatically obtaining the css rules of a site when the document.styleSheets[].cssRules
object is null?