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
 
_doImports(self, parentStyleSheet, baseurl=None)
handle all @import CSS stylesheet recusively 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, saveparsed=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

_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, saveparsed=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

use literal CSS from server or use the parsed version

you may want to use the server version until CSSParser is more stable or if you want to keep the stylesheet exactly as is