Created
November 12, 2013 03:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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