我正在将发送给用户的所有推文下载到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])
问题是csv包含一些奇怪的字符,我不知道如何解决它。
对于推文:
.@iamsrk’s breakout film #Baazigar also had this soothing romantic track
以CSV格式保存的数据为:
RT @RadioMirchi: .@iamsrk’s breakout film #Baazigar also had this soothing romantic track …
此处您可以看到'
已被’s
我已经看到其他非字母数字字符更奇怪的替换。我该如何解决这个问题?