我正在使用tweepy光标使用关键字搜索推文。我只想获取包含这些关键字的答复。我该怎么办?
以下是我的代码。
#!/usr/bin/python
# coding=utf-8
import tweepy
import pandas as pd
import csv # Import csv
auth = tweepy.auth.OAuthHandler("xxxxxxxxxxxxxx", "xxxxxxxxxxxx")
auth.set_access_token("xxxxxxxxxxxxxx",
"xxxxxxxxxxxxxx")
api = tweepy.API(auth)
# create list to append tweets to
tweets = []
for tweet in tweepy.Cursor(api.search,
q='තම්බි',
lang="si").items():
tweets.append(tweet)
if (not tweet.retweeted) and ('RT @' not in tweet.text):
# convert 'tweets' list to pandas.DataFrame
tweets_df = pd.DataFrame(vars(tweets[i]) for i in range(len(tweets)))
# define attributes you want
tweet_atts = [
'id',
'text', 'created_at'
]
# subset dataframe
tweets_df = tweets_df[tweet_atts]
# define file path (string) to save csv file to
FILE_PATH = (r'C:\Users\Home\PycharmProjects\sinhala_tweets\tweets.csv')
# use pandas to save dataframe to csv
tweets_df.to_csv(FILE_PATH)