I encountered Encoding Problems in the python code I wrote: SyntaxError: Non-ASCII character '\ xd3' in file crawler. py
Cause: the Code contains a part that needs to output Chinese characters, but this error occurs during running;
Error prompted to see this link: http://www.python.org/peps/pep-0263.html
Solution:
If any character other than ASCII code appears in python, you must declare the character format at the beginning of the Code.
Solution:
Add #-*-coding: UTF-8-*-at the beginning of the program -*-
~ Test] # cat crawler. py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Import urllib2
Import re
Solution 2:
Add # coding: UTF-8 at the beginning of the program
#! /Usr/bin/python
# Coding: UTF-8
Import urllib2
Import re
Solution 3:
Add the following code at the beginning of the program: # coding = UTF-8
#! /Usr/bin/python
# Coding = UTF-8
Import urllib2
Import re