Python: Scraping special Characters Writing to CSV

134 views Asked by At

Hello I am trying to scrape a website and its going fine, till the point I try to save the data into a csv via csv module writer. I traced back to the data and find out that 7 aƱos is the string which isn't allowing the data to store properly.

I READ A LOT ON THIS TOPIC BEFORE POSTING... BUT COULDN'T GRASP THE CONCEPT.

Python is throwing some encoding error which got me to reading and I found that csv module isn't capable of unicode.

Is there any suggestion?

1

There are 1 answers

0
NIKHIL RANE On

Try to use following solution

def sanitize_string(string):
    return string.replace('\t', '')

Try to encode the string using encode function

your_variable = sanitize_string("your string")
your_variable.encode('utf8')

Hope this will help you.