Package cssutils :: Package scripts :: Module csscapture :: Class CSSCapture |
[hide private]
[frames] | no frames]

# Class CSSCapture

source code

    object --+
             |
            CSSCapture

Retrieve all CSS stylesheets including embedded for a given URL. Optional setting of User-Agent used for retrieval possible to handle browser sniffing servers.

raises urllib2.HTTPError

Instance Methods | [hide private]
__init__(self, ua=None, log=None, defaultloglevel=20) initialize a new Capture object | source code
_doRequest(self, url) Does an HTTP request | source code
_createStyleSheet(self, href=None, media=None, parentStyleSheet=None, title=`u'````'`, cssText=None, encoding=None) returns CSSStyleSheet read from href or if cssText is given use that | source code
_doImports(self, parentStyleSheet, baseurl=None) handle all @import CSS stylesheet recursively found CSS stylesheets are appended to stylesheetlist | source code
_findStyleSheets(self, docurl, doctext) parse text for stylesheets fills stylesheetlist with all found StyleSheets | source code
capture(self, url, ua=None) Capture stylesheets for the given url, any HTTPError is raised to caller. | source code
saveto(self, dir, saveraw=False, minified=False) saves css in "dir" in the same layout as on the server internal stylesheets are saved as "dir/__INLINE_STYLE__.html.css" | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, ua=None, log=None, defaultloglevel=20) (Constructor) | source code
initialize a new Capture object ua init User-Agent to use for requests log supply a log object which is used instead of the default log which writes to sys.stderr defaultloglevel constant of logging package which defines the level of the default log if no explicit log given Overrides: object.__init__

### _doRequest(self, url) | source code
Does an HTTP request Returns: (response, url) url might have been changed by server due to redirects etc

### _createStyleSheet(self, href=None, media=None, parentStyleSheet=None, title=`u'````'`, cssText=None, encoding=None) | source code
returns CSSStyleSheet read from href or if cssText is given use that encoding used if inline style found, same as self.docencoding

### _findStyleSheets(self, docurl, doctext) | source code
parse text for stylesheets fills stylesheetlist with all found StyleSheets docurl to build a full url of found StyleSheets @href doctext to parse

### capture(self, url, ua=None) | source code
Capture stylesheets for the given url, any HTTPError is raised to caller. url to capture CSS from ua User-Agent to use for requests Returns StyleSheetList.

### saveto(self, dir, saveraw=False, minified=False) | source code
saves css in "dir" in the same layout as on the server internal stylesheets are saved as "dir/__INLINE_STYLE__.html.css" dir directory to save files to saveparsed save literal CSS from server or save the parsed CSS minified save minified CSS Both parsed and minified (which is also parsed of course) will loose information which cssutils is unable to understand or where it is simple buggy. You might to first save the raw version before parsing of even minifying it.