Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用搜索关键字检索特定数量的推文_Python_Tweets - Fatal编程技术网

Python 使用搜索关键字检索特定数量的推文

Python 使用搜索关键字检索特定数量的推文,python,tweets,Python,Tweets,你的问题需要更具描述性,但是如果你想通过搜索获得特定数量的tweet…你可以参考这个例子 进口粗花呢 导入csv导入csv 导入json 导入编解码器 导入日期时间 from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener import time s=raw_input('string'); try: file = open('keywo

你的问题需要更具描述性,但是如果你想通过搜索获得特定数量的tweet…你可以参考这个例子

进口粗花呢 导入csv导入csv 导入json 导入编解码器 导入日期时间

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time


s=raw_input('string');

try:
    file = open('keyword.txt', 'r')
    keyword=file.read()


    ckey ='CONSUMER KEY'
    csecret ='CONSUMER SECRET'
    atoken ='ACCESS TOKEN'
    asecret='ACCESS SECRET'

    class listener(StreamListener):

        def on_data(self, data):


           # print data

            tweet=data.split(',"text":"')[1].split('","source')[0]
            print (tweet)
            print ('\n')
            saveThis=tweet
            saveFile =open('projectdatabase.csv','a')
            saveFile.write(saveThis )
            saveFile.write('\n')
            saveFile.close()
            return True

        def on_error(self, status):
            print (status)


            auth=OAuthHandler(ckey, csecret)
            auth.set_access_token(atoken, asecret)
            twitterStream=Stream(auth, listener())
            twitterStream.filter(track=[keyword])

except Exception:

每个人都需要帮助,这就是为什么他们会提出问题。如果你需要帮助,你需要更具体地说明你需要什么帮助。代码不起作用吗?它怎么不起作用?如果它真的起作用了该怎么办?会发生什么?
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#Access tokens 
auth = tweepy.auth.OAuthHandler('#######', '#######')
auth.set_access_token('########', '######')

api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('result1234.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
f = codecs.open('abc.csv',encoding='utf-8', mode='a')

for tweet in tweepy.Cursor(api.search, 
                    q="Interstellar", 
                    since="2015-01-30", 
                    until="2015-02-01",


                lang="en").items(10000):
#Write a row to the csv file/ I use encode utf-8
print tweet;
csvWriter.writerow([tweet])