Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Created November 12, 2013 03:34
Show Gist options
  • Select an option

  • Save cwebber314/7425048 to your computer and use it in GitHub Desktop.

Select an option

Save cwebber314/7425048 to your computer and use it in GitHub Desktop.
I use this gist to concatenate stand-along html files or embed one html file in a master html file.
from bs4 import BeautifulSoup
fn = r'solution1_printed.htm'
f = open(fn, 'r')
html = f.read()
f.close()
soup = BeautifulSoup(html)
body = soup.body
replaces = [
('h3', 'h4'),
('h2', 'h2'),
('h1', 'h2'),
]
for pair in replaces:
tags = body.findAll(pair[0])
for tag in tags:
tag.name = pair[1]
fn = 'foo.html'
f = open(fn, 'w')
f.write(body.encode_contents())
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment