Google+ Tools
Make Google+ profile picture
Make Google plus banners for profile
Create and share your Google Plus profile banners.

Profile image for mrk studios dugo on April 18, 2012

A python script to extract inline CSS in HTML made with some graphical tool (like iWeb).

Only BeautifulSoup installed.

Language
Python
Tags

python css inline extractor


#!/usr/bin/python

from BeautifulSoup import BeautifulSoup as BS

import sys

bs = BS(open(sys.argv[1]).read())

count = 0
styles = []
for t in bs.findAll(True):
    
    if  t.get('style'):
        
        myclass = "extracted_%d" % count
        styles.append( ".%s { %s }" % (myclass,t.get('style'),))
        
        del t['style']
        
        # has class
        if t.get('class'):
            t['class'] = t['class'] + " "+ myclass
        # no has class
        else:
            t['class'] = myclass
        
        count+=1

print "\n".join(styles)
print bs.prettify()

Comments

blog comments powered by Disqus