Last active
November 1, 2023 10:34
-
-
Save sohang3112/adcc6daf7c3eb858c09a54573e965e11 to your computer and use it in GitHub Desktop.
Render an HTML string in the default web browser
This file contains 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
import webbrowser | |
from tempfile import NamedTemporaryFile | |
def view_html(html: bytes, **kwargs) -> bool: | |
""" | |
Open HTML input string as a webpage in default browser | |
@return - True if page opened successfully, False otherwise | |
""" | |
with NamedTemporaryFile(suffix='.html', delete=False, **kwargs) as f: | |
f.write(html) | |
return webbrowser.open(f.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: In a Jupyter Notebook, HTML can be displayed inline directly using IPython.display: