【发布时间】:2020-04-30 19:44:42
【问题描述】:
我正在学习将 Twitter API 与 Tweepy 一起使用。我需要提取原始推文数据的帮助——这意味着没有缩短的 URL。例如,This Tweet 显示一个 YouTube 链接,但在被 API 解析时,会打印一个 t.co 链接。如何打印显示的文本?感谢您的帮助。
注意:我和this question有类似的担忧,但不一样。
功能代码:
def get_tweets(username):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
# Call api
api = tweepy.API(auth)
tweets = api.user_timeline(screen_name=username)
# Empty Array
tmp=[]
# create array of tweet information: username,
# tweet id, date/time, text
tweets_for_csv = [tweet.text for tweet in tweets] # CSV file created
for j in tweets_for_csv:
# Append tweets to the empty array tmp
tmp.append(j)
dict1 = {}
punctuation = '''`~!@#$%^&*(){}[];:'".,\/?'''
tmps = str(tmp)
for char in tmps:
if char in punctuation:
tmps = tmps.replace(char," ")
tmps2 = tmps.split(" ")
a = 0
while a < len(tmps2):
for b in tmps2:
dict1[a] = b
a += 1
【问题讨论】: