Which codec can help me decode the html source? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Which codec can help me decode the html source? (/thread-23635.html) |
Which codec can help me decode the html source? - vivekagrey - Jan-09-2020 I want to show a web page(actually a google map) in tkinter
import urllib.request from tk_html_widgets import HTMLLabel from tkinter import * root = tk.Tk() text = HTMLLabel(root) text.pack(fill="both", expand=True) text.set_html(urllib.request.urlopen("https://www.google.com" ).read().decode("UTF-8")) text.fit_height() root.mainloop() RE: Which codec can help me decode the html source? - Larz60+ - Jan-09-2020 You need to take a few tutorials before attempting this. Search YouTube for tkinter canvas tutorial RE: Which codec can help me decode the html source? - vivekagrey - Jan-09-2020 I have tried a lot but I am unable to open the google map in tkinter. help me with it. I went through but still I was unable to solve the error import tkinter from gmplot import * from tk_html_widgets import HTMLLabel root = tkinter.Tk() gmap = gmplot.GoogleMapPlotter(28.5355, 77.3910, 18) #gmap.apikey = "AIzaSyDeRNMnZ__VnQDiATiuz4kPjF_c9r1kWe8" gmap.draw( "map_key.html" ) frame = tkinter.Frame(root, height = 200, width = 200, bg = "yellow").pack() html = open("map_key.html", "r").read() html_label = HTMLLabel(frame, html=html, height = 100) html_label.pack(fill="both", expand=True) html_label.fit_height() root.mainloop() RE: Which codec can help me decode the html source? - Larz60+ - Jan-09-2020 see an example here: https://stackoverflow.com/questions/5444438/display-google-map-api-in-python-tkinter-window RE: Which codec can help me decode the html source? - DeaD_EyE - Jan-10-2020 (Jan-09-2020, 05:31 PM)vivekagrey Wrote: I want to show a web page(actually a google map) in tkinter The encoding is iso-8859-1, better known as latin1. Not all webpages are encoded with utf8. You need to get this information from headers or you just use the requests module. import urllib.request from tk_html_widgets import HTMLLabel from tkinter import Tk root = Tk() text = HTMLLabel(root) text.pack(fill="both", expand=True) req = urllib.request.urlopen("https://www.google.com" ) encoding = req.headers.get_content_charset() text.set_html(req.read().decode(encoding)) text.fit_height() root.mainloop()But this is not the complete solution. I guess you need something which is also able to parse and execute javascript. If you run this code, you see all JavaScripts in clear text. |