How to combine two HTML files into one in Python

Question:

I created two plotly charts and saved them as HTML files separately. Is there a way to combine them into one HTML file? For example I can do this with PDF files using the following code:

from PyPDF2 import PdfFileMerger, PdfFileReader
merger = PdfFileMerger()

merger.append(PdfFileReader(open(filename1, 'rb')))
merger.append(PdfFileReader(open(filename2, 'rb')))

merger.write("merged.pdf")

Is there any library that can merge HTML files this way?

Asked By: beridzeg45

||

Answers:

Try using the python library htmlmerger
Ex:-

from htmlmerger import HtmlMerger
merger = HtmlMerger(input_directory="my_htmls/")  # result will be in my_htmls/merged.html
merger.merge(clean=True)  # or clean=False to keep the individual files (default behavior)
Answered By: Alekhya
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.