giuseppegambino/Scraping-TripAdvisor-with-Python-2020

UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f604' in position 290: character maps to <undefined>"

Didiergrimaldi opened this issue · 1 comments

hello
i'm using the new code that split "things to do" with restaurant.
Restaurant runs well 7 times then i have this error:

"---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
in
19 review = container[j].find_element_by_xpath(".//p[@Class='partial_entry']").text.replace("\n", " ")
20
---> 21 csvWriter.writerow([date, rating, title, review])
22
23 # change the page

~\Anaconda3\lib\encodings\cp1252.py in encode(self, input, final)
17 class IncrementalEncoder(codecs.IncrementalEncoder):
18 def encode(self, input, final=False):
---> 19 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
20
21 class IncrementalDecoder(codecs.IncrementalDecoder):

UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f604' in position 290: character maps to "

please help
Didier

Hello Didier,
The problem is probably that you found an emoji in a review.

With python3 or greater you shouldn't run into such a problem, but you can try to force the text encoding by editing line 27:

  • FROM: csvFile = open(path_to_file, 'a')

  • TO: csvFile = open(path_to_file, 'a', encoding="utf-8")

Let me know if you have solved the problem now, so in case i update the code :)

Giuseppe.