Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.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
仅使用tweepy和python从英国获取推文_Python_Location_Tweepy - Fatal编程技术网

仅使用tweepy和python从英国获取推文

仅使用tweepy和python从英国获取推文,python,location,tweepy,Python,Location,Tweepy,我正在尝试使用python中的tweepy来获取推文,但在11月的一个星期内,我只能从英国获取推文,这样我就可以找到这段时间讨论的热门话题。我正在尝试获得大约1000条推文 然而,无论我尝试什么,似乎都只收到一条推特(键替换为xxx表示敏感,但它们确实有效),我尝试输入long和lat,但发现这也很难覆盖整个英国。感谢您的指导 下面的代码返回,但当我删除最大数量的项目时,它只返回一条tweet,有什么想法吗 代码 import datetime start_date = datetime.dat

我正在尝试使用python中的tweepy来获取推文,但在11月的一个星期内,我只能从英国获取推文,这样我就可以找到这段时间讨论的热门话题。我正在尝试获得大约1000条推文

然而,无论我尝试什么,似乎都只收到一条推特(键替换为xxx表示敏感,但它们确实有效),我尝试输入long和lat,但发现这也很难覆盖整个英国。感谢您的指导

下面的代码返回,但当我删除最大数量的项目时,它只返回一条tweet,有什么想法吗

代码

import datetime
start_date = datetime.datetime(2020, 11, 15, 0, 0, 0)
end_date =  datetime.datetime(2020, 11, 8, 0, 0, 0)

consumer_key = 'xxx'
consumer_secret = 'xxx'
access_key = 'xxx'
access_secret = 'xxx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
places = api.geo_search(query="UK",granularity="country")
place_id = places[0].id
max_tweets = 1000
searched_tweets = tweepy.Cursor(api.search, q="place:%s" % place_id,  lang="en", tweet_mode="extended", since = start_date, until = end_date).items(max_tweets)
df = pd.DataFrame(columns=["date", "tweet", "user", "location"])
searched_tweets = tweepy.Cursor(api.search, q="place:%s" % place_id,  lang="en", tweet_mode="extended", since = start_date, until = end_date).items(max_tweets)
df = pd.DataFrame(columns=["date", "tweet", "user", "location"])