Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created November 8, 2008 22:08
Show Gist options
  • Save tommorris/23144 to your computer and use it in GitHub Desktop.
Save tommorris/23144 to your computer and use it in GitHub Desktop.
import sys
from BeautifulSoup import BeautifulSoup, Tag
css = ""
doc_file = open(sys.argv[1])
doc_string = '\n'.join(doc_file.readlines())
doc = BeautifulSoup(doc_string)
for i in doc.findAll("style"):
css = css + str("".join(i.contents)) + "\n"
i.extract()
link_tag = Tag(doc, "link")
link_tag['rel'] = "stylesheet"
link_tag['type'] = "text/css"
link_tag['href'] = "output.css"
doc.head.insert(-1, link_tag)
css_file = open("output.css", "w")
css_file.write(css)
print doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment