search

Home  >  Q&A  >  body text

Python crawler character encoding error problem

Crawling the content of Baidu Encyclopedia

response=urllib2.urlopen(url)

    if response.getcode()!=200:
        return None
    html=response.read()
    return html.decode("UTF-8")
    

Write another file. When writing, 'gbk' codec can't encode character 'xa0' in position 15 appears.
I use UTF8 encoding to write. How does it have anything to do with gbk? ? ?

曾经蜡笔没有小新曾经蜡笔没有小新2755 days ago543

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 11:04:47

    Please post the complete code and exception information

    reply
    0
  • Cancelreply