目标:需要了解如何将下面 api 搜索中的数据解析为 CSV 文件。搜索以以下格式返回结果:
[(u'Bertille Maciag', 10), (u'Peter Prior', 5), (u'Chris OverPar Duguid', 4), (u
'Selby Dhliwayo', 4), (u'FakeBitch!', 4), (u'Django Unchianed UK', 4), (u'Padrai
g Lynch ', 4), (u'Jessica Gunn', 4), (u'harvey.', 4), (u'Wowphotography', 3)]
我是 python 的新手,任何帮助将不胜感激
import twitter, json, operator
#Construct Twitter API object
searchApi = twitter.Twitter(domain="search.twitter.com")
#Get trends
query = "#snow"
tweeters = dict()
for i in range(1,16):
response = searchApi.search(q=query, rpp=100, page=i)
tweets = response['results']
for item in tweets:
tweet = json.loads(json.dumps(item))
user = tweet['from_user_name']
#print user
if user in tweeters:
# print "list already contains", user
tweeters[user] += 1
else:
tweeters[user] = 1
sorted_tweeters = sorted(tweeters.iteritems(), key=operator.itemgetter(1), reverse=True)
print len(tweeters)
print tweeters
print sorted_tweeters[0:10]
print 'Done!'