Package cssutils :: Module script :: 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) Do an HTTP request | source code
_createStyleSheet(self, href=None, media=None, parentStyleSheet=None, title=`u'````'`, cssText=None, encoding=None) Return CSSStyleSheet read from href or if cssText is given use that. | source code
_findStyleSheets(self, docurl, doctext) parse text for stylesheets fills stylesheetlist with all found StyleSheets | source code
_doImports(self, parentStyleSheet, base=None) handle all @import CSS stylesheet recursively found CSS stylesheets are appended to stylesheetlist | source code
capture(self, url) Capture all stylesheets at given URL's HTML document. | 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
Do an HTTP request Return (url, rawcontent) 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
Return 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) | source code
Capture all stylesheets at given URL's HTML document. Any HTTPError is raised to caller. url to capture CSS from Returns `cssutils.stylesheets.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.