Advertisement
Python253

html2bin

Mar 13th, 2024
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: html2bin.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script converts an HTML file (.html) to a binary file (.bin).
  10. It reads the HTML content and writes it to a binary file after encoding it in UTF-8.
  11.  
  12. Requirements:
  13. - Python 3.x
  14.  
  15. Usage:
  16. 1. Save this script as 'html2bin.py'.
  17. 2. Ensure your HTML file ('example.html') is in the same directory as the script.
  18. 3. Run the script.
  19. 4. The converted binary file ('html2bin.bin') will be generated in the same directory.
  20.  
  21. Note: Adjust the 'html_filename' and 'bin_filename' variables in the script as needed.
  22. """
  23. def html_to_bin(html_filename, bin_filename):
  24.     with open(html_filename, 'r') as htmlfile, open(bin_filename, 'wb') as binfile:
  25.         binfile.write(htmlfile.read().encode('utf-8'))
  26.  
  27. if __name__ == "__main__":
  28.     html_filename = 'example.html'
  29.     bin_filename = 'html2bin.bin'
  30.     html_to_bin(html_filename, bin_filename)
  31.     print(f"Converted '{html_filename}' to '{bin_filename}'.")
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement