Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created November 14, 2012 14:00
Show Gist options
  • Select an option

  • Save daGrevis/4072253 to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/4072253 to your computer and use it in GitHub Desktop.
Prettify HTML
#!/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