jessica jessica - 5 months ago 34
Javascript Question

How to open an HTML file in the browser from Python?

I am trying to open an HTML file from Python but my script just displays the contents of the HTML file in Python instead of opening it in the browser. How can I fix this problem? How can I open the HTML file in my Chrome browser?


<a href="" target="_blank" title="Success vs Failure" style="display: block; text-align: center;"><img src="" alt="Success vs Failure" style="max-width: 100%;width: 600px;" width="600" onerror="this.onerror=null;this.src='';" /></a>
<script data-plotly="user001:2" src="" async></script>

Python 2.7 script:

import urllib
page = urllib.urlopen('testdata.html').read()
print page


Try specifying the "file://" at the start of the URL.

// Also, use the absolute path of the file:'file://' + os.path.realpath(filename))


import webbrowser
new = 2 # open in a new tab, if possible

// open a public URL, in this case, the webbrowser docs
url = "",new=new)

// open an HTML file on my own (Windows) computer
url = "file://d/testdata.html",new=new)