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
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:
with open('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:
with open('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)