How to make HTML files open in Chrome using Python? Last Updated : 21 Mar, 2024 Comments Improve Suggest changes Like Article Like Report Prerequisites: Webbrowser HTML files contain Hypertext Markup Language (HTML), which is used to design and format the structure of a webpage. It is stored in a text format and contains tags that define the layout and content of the webpage. HTML files are widely used online and displayed in web browsers. To preview HTML files, we make the use of browsers, like Google Chrome, Mozilla Firefox, Apple Safari etc. The task of creating and previewing HTML files can be automated with the help of python scripts. Here are a few ways how we can open HTML files on chrome: Method 1: Using os and webbrowser The webbrowser module in python provides a high-level interface to allow displaying Web-based documents to users, and the os module provides a portable way of using operating system dependent functionalities (like reading or writing files, manipulating file paths etc.). So let's see how a combination of these both can help us to open an HTML page in Chrome browser: Function used: open_new_tab() function is used to open html file in a new tab of your default browser. Syntax: open_new_tab(filename) Approach: Import moduleOpen and Create fileĀ Add html codeĀ Write code to fileClose fileOpen file in browser window Example: Python3 # creating and viewing the html files in python import webbrowser import os # to open/create a new html file in the write mode f = open('GFG.html', 'w') # the html code which will go in the file GFG.html html_template = """ <html> <head></head> <body> <p>Geeks For Geeks</p> </body> </html> """ # writing the code into the file f.write(html_template) # close the file f.close() # 1st method how to open html files in chrome using filename = 'file:///'+os.getcwd()+'/' + 'GFG.html' webbrowser.open_new_tab(filename) Output: Method 2: Without using the 'os' module: If the HTML file is in the same directory as that of the python script, then there is no need of defining the file path with the os module. We can simply run the html file in new browser using the given steps: Approach Create a html file that you want to openIn Python, Import moduleCall html file using open_new_tab() Example: Python3 Import webbrowser webbrowser.open_new_tab('GFG.html') Output: Comment More infoAdvertise with us Next Article How to make HTML files open in Chrome using Python? mprerna802 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 python-utility python-os-module +1 More Practice Tags : python Similar Reads How to parse local HTML file in Python? Prerequisites: Beautifulsoup Parsing means dividing a file or input into pieces of information/data that can be stored for our personal use in the future. Sometimes, we need data from an existing file stored on our computers, parsing technique can be used in such cases. The parsing includes multiple 5 min read How to make an HTML link to open a folder ? To create a link to a file or folder, you need to use an <a href > tag. HTML can be used to open a folder from our local storage. To open a folder from our local storage, use the 'href' attribute of HTML. In the href attribute, we specify the path of our folder. Syntax: <a href="Path"> 1 min read Read Html File In Python Using Pandas We are given an HTML file that contains one or more tables, and our task is to extract these tables as DataFrames using Python. For example, if we have an HTML file with a table like this:<table> <tr><th>Code</th><th>Language</th><th>Difficulty</th> 4 min read How to write to an HTML file in Python ? Python language has great uses today in almost every field, it can be used along with other technologies to make our lives easier. One such use of python is getting the data output in an HTML file. We can save any amount of our input data into an HTML file in python using the following examples in t 2 min read How To Send Files Using Python Built-In Http Server Python's built-in HTTP server offers a straightforward way to share files over a local network or the internet without the need for complex setups. In this tutorial, we'll walk through the step-by-step process of using Python's built-in HTTP server to send files to clients. Setting Up the HTTP Serve 2 min read Create HTML User Interface using Eel in Python Eel is a Python library for making simple offline HTML/JS GUI apps, with full access to Python capabilities and libraries. Eel hosts a local webserver, then lets you annotate functions in Python so that they can be called from JavaScript, and vice versa.InstallationTo install this module, type the b 2 min read How to Use CSS in Python Flask Flask is a popular web framework for Python that makes it easy to build web applications. One of the key elements of any web application is styling, which is where CSS (Cascading Style Sheets) comes in. CSS allows us to control the look and feel of our web pages, making them more attractive and user 3 min read Convert HTML source code to JSON Object using Python In this post, we will see how we can convert an HTML source code into a JSON object. JSON objects can be easily transferred, and they are supported by most of the modern programming languages. We can read JSON from Javascript and parse it as a Javascript object easily. Javascript can be used to make 3 min read Generate HTML using tinyhtml module in Python Creating HTML can sometimes be tedious tasks and difficult to debug and error-prone. A way to solve this is using some library which can take care of the opening and closing div, etc, which can reduce chances for mistakes. We will use the tinyhtml module for this purpose. This module provides a set 3 min read How to convert CSV File to PDF File using Python? In this article, we will learn how to do Conversion of CSV to PDF file format. This simple task can be easily done using two Steps : Firstly, We convert our CSV file to HTML using the PandasIn the Second Step, we use PDFkit Python API to convert our HTML file to the PDF file format. Approach: 1. Con 3 min read Like