Created
November 14, 2012 14:00
-
-
Save daGrevis/4072253 to your computer and use it in GitHub Desktop.
Prettify HTML
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
| #!/usr/bin/env python2 | |
| import sys | |
| import argparse | |
| import BeautifulSoup | |
| def pretty_html(html): | |
| soup = BeautifulSoup.BeautifulSoup(html) | |
| return soup.prettify() | |
| def main(): | |
| arg_parser = argparse.ArgumentParser() | |
| arg_parser.add_argument("-f", "--file") | |
| args = arg_parser.parse_args() | |
| try: | |
| with open(args.file) as input_file: | |
| print pretty_html(input_file.read()) | |
| print "\nHTML prettified!" | |
| except IOError: | |
| print "File does not exist!" | |
| sys.exit() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment