Python Forum
Which codec can help me decode the html source?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Which codec can help me decode the html source?
#1
I want to show a web page(actually a google map) in tkinter
Error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 12619: invalid start byte
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()
Reply
#2
You need to take a few tutorials before attempting this.
Search YouTube for tkinter canvas tutorial
Reply
#3
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[Image: qlh3hb]

[Image: qlh5ap]


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()
Reply
#4
see an example here: https://stackoverflow.com/questions/5444...ter-window
Reply
#5
(Jan-09-2020, 05:31 PM)vivekagrey Wrote: I want to show a web page(actually a google map) in tkinter
Error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 12619: invalid start byte

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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 16: invalid cont Melcu54 3 4,999 Mar-26-2023, 12:12 PM
Last Post: Gribouillis
  Decode string ? JohnnyCoffee 1 823 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 931 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  [SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec Winfried 1 1,034 Nov-16-2022, 11:41 AM
Last Post: Winfried
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 34: character Melcu54 7 19,014 Sep-26-2022, 10:09 AM
Last Post: Melcu54
  ASCII-Codec in Python3 [SOLVED] AlphaInc 4 6,154 Jul-07-2021, 07:05 PM
Last Post: AlphaInc
  reading html and edit chekcbox to html jacklee26 5 3,080 Jul-01-2021, 10:31 AM
Last Post: snippsat
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call AkaAndrew123 1 3,454 Apr-28-2021, 08:16 AM
Last Post: AkaAndrew123
  codec for byte transparency Skaperen 7 3,855 Sep-25-2020, 02:20 AM
Last Post: Skaperen
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,570 Sep-18-2020, 10:10 PM
Last Post: tienttt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020