Skip to content

Instantly share code, notes, and snippets.

@kroger
Created June 20, 2011 16:39
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 kroger/1035962 to your computer and use it in GitHub Desktop.
Save kroger/1035962 to your computer and use it in GitHub Desktop.
Remove html elemment
import lxml.html
page = lxml.html.parse("final.html").getroot()
images = page.xpath("//img")
for node in images:
node.getparent().remove(node)
with open("out.html", 'w') as outhtml:
outhtml.write(lxml.html.tostring(page))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment