• Python3.6(windows系统)解决编码问题


    Python3.6(windows系统)解决编码问题

    1,py文件代码:

    import urllib.request
    url = "http://www.douban.com/"
    webPage = urllib.request.urlopen(url)
    data = webPage.read()
    data = data.decode('UTF-8')
    print(data)
    print(type(webPage))
    print(webPage.geturl())
    print(webPage.info())
    print(webPage.getcode())

    2,执行出现字符编码异常:

    python, 'gbk' codec can't encode character 'u2122' in position 42161: illegal multibyte sequence

    3,解决方案:

    #增加字符编码转换
    import sys, io
    # Change default encoding to utf8  
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') 
  • 相关阅读:
    杭电1827
    hdu 3118
    poj 2060
    hdu 2236
    poj 2226
    poj 1719
    poj 1466
    poj 3160
    骑士飞行棋笔记
    基础测试学习笔记
  • 原文地址:https://www.cnblogs.com/lizm166/p/8128212.html
Copyright © 2020-2023  润新知