Saturday, January 13, 2007

Python CSS parsing.

So you want to parse a website?

Python has some pretty cool html, rss, and atom parsing modules. There is also a promising CSS parser. This parser is cssutils.

http://cthedot.de/cssutils/

Parsing CSS is one part which can occasionally come in handy. Say you want to figure out how big a piece of text will display on a page? Without CSS parsing you can not test this.

You want to check to see if a piece of html is displayed at all? Well assuming we ignore javascript, CSS can be used to disable parts of a website with display:none or by setting the visibility or transparency. So this is another reason why you might want to parse CSS.

It's also handy if you are using CSS in your own non web based GUI engine. CSS is a fairly well understood language. So using it instead of your own format might be a good idea.


Above are some reasons why you might want to parse CSS with python. However I'm sure there are others which might pop into your head if you are a web developer.

Thanks to Christof Hoeke for providing one of the missing batteries for a modern WWW (cssutils).



Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

1 comment:

TheOne said...

"Parsing CSS is one part which can occasionally come in handy. Say you want to figure out how big a piece of text will display on a page? Without CSS parsing you can not test this."

Have you done anything like this? I am also trying something like this, but not been able to do so effectively. If you have some sample code. please send it to me.