A rudimentary question. I'm trying to get html code using urllib in python3.
request=urllib.request.Request(url)
response=urllib.request.urlopen(request)
html=response.read().decode('utf-8')
I'm getting the source code as above. I can get it well when the page I'm getting is utf-8, but if it's encoded with shift-jis
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 228: invalid start byte
I get an error. I think it will work if I convert "shift-jis" of "bytes" to "utf-8" of "bytes". Is that possible?
python python3
© 2024 OneMinuteCode. All rights reserved.