Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open html file?

I have html file called test.html it has one word בדיקה.

I open the test.html and print it's content using this block of code:

file = open("test.html", "r") print file.read() 

but it prints ??????, why this happened and how could I fix it?

BTW. when I open text file it works good.

Edit: I'd tried this:

>>> import codecs >>> f = codecs.open("test.html",'r') >>> print f.read() ????? 
like image 954
david Avatar asked Dec 02 '14 06:12

david


People also ask

What program can open a HTML file?

Any web browser, such as Edge, Firefox, Chrome or Opera, will open and properly display HTM and HTML files.

How do I open HTML in browser?

To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.

How do I open an HTML file in Chrome?

Fire up Chrome and jump to the webpage you want to view the HTML source code. Right-click the page and click on “View Page Source,” or press Ctrl + U, to see the page's source in a new tab. A new tab opens along with all the HTML for the webpage, completely expanded and unformatted.

Why is my HTML file not opening?

Check if the file is saved with a UTF-8 encoding. If that doesn't work, try installing another browser or using Edge/Safari/Internet Explorer or whatever built-in browser you have. It is saved as index.


2 Answers

import codecs f=codecs.open("test.html", 'r') print f.read() 

Try something like this.

like image 83
vks Avatar answered Oct 05 '22 13:10

vks


I encountered this problem today as well. I am using Windows and the system language by default is Chinese. Hence, someone may encounter this Unicode error similarly. Simply add encoding = 'utf-8':

with open("test.html", "r", encoding='utf-8') as f:     text= f.read() 
like image 37
Chen Mier Avatar answered Oct 05 '22 14:10

Chen Mier