I want to create a HTML file in my code and open a new tab in chrome with it.
this is the code I have. It works:
with open('mysite.html','w') as f:
f.write('<html>')
f.write('<head>')
f.write('<title>Table of contents</title>')
f.write('</head>')
f.write('<body>')
# myhtmltable is a pandas dataframe containing only text
f.write(myhtmltable)
f.write('</body>')
f.write('</html>')
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open('mysite.html')
As you can see I create a file in the local folder where the .py lives.
Is it possibly to create the HTML file on the fly and not having to access the disc, i.e. saving the file and reading it with webbrowser?
So If I have something like:
myhtml = '<html><head><title>Table of contents</title></head><body>this is the body</body></html>'
can I send it directly to a chrome tab?
Here there are two solutions but both creating a local file: Launch HTML code in browser (that is generated by BeautifulSoup) straight from Python