I am downloading all the tweets sent to a user into a csv
auth = tweepy.OAuthHandler(cons_tok, cons_sec)
auth.set_access_token(app_tok, app_sec)
twitter_api = tweepy.API(auth,retry_delay=5,retry_errors=set([401, 404, 500, 503]),
wait_on_rate_limit=True )
#Open CSV
myfile = open('teststream.csv', 'w')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
#Search for tweets sent to a particular user
search_results = tweepy.Cursor(twitter_api.search, q="@iamsrk").items(5)
try:
for results in search_results:
print(results.text)
item = (results.text).encode('utf-8').strip()
wr.writerow([item])
The problem is that the csv contains some weird characters and I am not sure how to fix it.
For the tweet:
.@iamsrk’s breakout film #Baazigar also had this soothing romantic track
The data saved in CSV is this:
RT @RadioMirchi: .@iamsrk’s breakout film #Baazigar also had this soothing romantic track …
Here as you can see '
is getting replaced by ’s
I have seen some more weird replacements for other non-alphanumerical characters. How can I fix this?