내가 가져 오는 많은 트윗에서 읽은이 문제가 있습니다.
b'I posted a new photo to Facebook'
나는 b그것이 바이트 라는 것을 나타냅니다. 그러나 이것은 내가 작성하는 CSV 파일에서 b사라지지 않고 향후 코드를 방해 하기 때문에 문제가 있음을 증명 합니다.
b내 텍스트 줄 에서이 접두사 를 제거하는 간단한 방법이 있습니까?
utf-8로 인코딩 된 텍스트가 필요하거나 tweepy가 웹에서 텍스트를 가져 오는 데 문제가있는 것 같습니다.
분석중인 링크 콘텐츠는 다음과 같습니다.
https://www.dropbox.com/s/sjmsbuhrghj7abt/new_tweets.txt?dl=0
new_tweets = 'content in the link'
코드 시도
outtweets = [[tweet.text.encode("utf-8").decode("utf-8")] for tweet in new_tweets]
print(outtweets)
오류
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-21-6019064596bf> in <module>()
1 for screen_name in user_list:
----> 2 get_all_tweets(screen_name,"instance file")
<ipython-input-19-e473b4771186> in get_all_tweets(screen_name, mode)
99 with open(os.path.join(save_location,'%s.instance' % screen_name), 'w') as f:
100 writer = csv.writer(f)
--> 101 writer.writerows(outtweets)
102 else:
103 with open(os.path.join(save_location,'%s.csv' % screen_name), 'w') as f:
C:\Users\Stan Shunpike\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 characters in position 64-65: character maps to <undefined>