Unicodeencodeerror: 'cp949' Codec Can't Encode Character '\u20a9' In Position 90: Illegal Multibyte Sequence
I'm a python beginner. I'm trying to crawl google play store and export to csv file. But I got a error message. UnicodeEncodeError: 'cp949' codec can't encode character '\u20a9' in
Solution 1:
Python 3 opens text files in the locale default encoding; if that encoding cannot handle the Unicode values you are trying to write to it, pick a different codec:
withopen('result.csv', 'w', encoding='UTF-8', newline='') as f:
That'd encode any unicode strings to UTF-8 instead, an encoding which can handle all of the Unicode standard.
Note that the csv
module recommends you open files using newline=''
to prevent newline translation.
You also need to open the file just once, outside of the for
loop:
withopen('result.csv', 'w') as f: # Just use 'w' mode in 3.x
fields = ('title', 'developer', 'developer_link', 'price', 'rating', 'reviewers',
'downloads', 'date_published', 'operating_system', 'content_rating',
'category')
w = csv.DictWriter(f, )
w.writeheader()
for div in soup.findAll( 'div', {'class' : 'details'} ):
## build app_details#
w.writerow(app_details)
Post a Comment for "Unicodeencodeerror: 'cp949' Codec Can't Encode Character '\u20a9' In Position 90: Illegal Multibyte Sequence"