Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.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 获取包含hashtags的tweets-Teepy_Python_Twitter_Tweepy - Fatal编程技术网

Python 获取包含hashtags的tweets-Teepy

Python 获取包含hashtags的tweets-Teepy,python,twitter,tweepy,Python,Twitter,Tweepy,我有一个使用Tweepy API的基本程序。它本质上是从用户那里获取推文并将其输出到终端。理想情况下,我希望这是自动化的,因此当用户发tweet时,程序将看到它并显示tweet。但这是下一次的问题 然而,我现在想做的是抓取只有标签的推文 我该怎么办?我希望这是一个参数,我可以添加在时间轴函数内 以下是我目前掌握的代码片段: import tweepy import twitter_credentials auth = tweepy.OAuthHandler(twitter_credential

我有一个使用Tweepy API的基本程序。它本质上是从用户那里获取推文并将其输出到终端。理想情况下,我希望这是自动化的,因此当用户发tweet时,程序将看到它并显示tweet。但这是下一次的问题

然而,我现在想做的是抓取只有标签的推文

我该怎么办?我希望这是一个参数,我可以添加在时间轴函数内

以下是我目前掌握的代码片段:

import tweepy
import twitter_credentials

auth = tweepy.OAuthHandler(twitter_credentials.CONSUMER_KEY, twitter_credentials.CONSUMER_SECRET)
auth.set_access_token(twitter_credentials.ACCESS_TOKEN, twitter_credentials.ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

stuff = api.user_timeline(screen_name = 'XXXXXX', count = 10, include_rts = False)

for status in stuff:
    print(status.text)

对于简单的用例,您可以在搜索字符串中使用
#
,例如:

api = tweepy.API(auth,wait_on_rate_limit=True)

tweet in tweepy.Cursor(api.search,q="#",count=100).items():
    print(tweet)

这将为您提供包含任何hastag的tweet。

当我使用该示例时,我在tweepy.Cursor(api.search,q=“#”,count=100)中收到一条错误tweet。items(10):语法错误:无效语法