Skip to content

Instantly share code, notes, and snippets.

@dietmarw
Created January 25, 2012 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dietmarw/1675530 to your computer and use it in GitHub Desktop.
Save dietmarw/1675530 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from pyquery import PyQuery as pq
import codecs
def convert_image(i, node):
print node
node = pq(node)
uri = node.attr("src")
if uri:
print "converting", uri
src = "".replace("M", "X")
node.attr("src", src)
with codecs.open("old-html-tmp/Modelica.Fluid.html", encoding="utf-8") as fh:
html = fh.read()
doc = pq(html)
doc.find("img").each(convert_image)
print doc.__html__() # __html__ method avoids escaping -- TODO: retain doctype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment