我試圖使用tweepy下載推文位置而不是用戶位置。目前,我可以下載用戶位置的推文,但即使geo_enabled
返回True,我也無法獲取推文位置。通過推文位置和用戶位置刮推文
例如,假設user_a
來自紐約,但他來自加利福尼亞的推文。我希望用戶位置紐約和推特位置加州。
代碼:
import tweepy
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import pandas as pd
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf8')
ckey = 'key'
csecret = 'secret'
atoken = 'token'
asecret = 'secret'
#csvfile = open('StreamSearch.csv','a')
#csvwriter = csv.writer(csvfile, delimiter = ',')
class StdOutListener(StreamListener):
def __init__(self, api=None):
super(StdOutListener, self).__init__()
self.num_tweets = 0
def on_data(self, data):
self.num_tweets += 1
if self.num_tweets < 5: #Remove the limit of no. of tweets to 5
print data
return True
else:
return False
def on_error(self, status):
print status
l = StdOutListener()
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
stream = Stream(auth, l)
stream.filter(locations = [80.10,12.90,80.33,13.24]) #user location
輸出
userLocation, userTimezone, Coordinates,GeoEnabled, Language, TweetPlace
London,UK Amsterdam FALSE en null
Aachen,Germany Berlin TRUE de null
Kewaunee Wi TRUE en null
Connecticut, Eastern Time (US & Canada) TRUE en null
TRUE en null
Lahore, City of Gardens London TRUE en null
NAU class of 2018. Arizona FALSE en null
FALSE en null
Pacific Time (US & Canada) FALSE en null
上面給定的輸出被清潔的海量數據的版本。即使啓用了Geolocation
,我也無法獲取推文位置,也無法獲得推文位置co-ordinates
。
這個非常廣泛的問題,讓我們知道你已經嘗試過。 – SIslam
@SIslam包括代碼和輸出 –
可能是相關的 - http://stackoverflow.com/a/16892093/4065350 –