0
我想從twitter獲取推文並保存到我嘗試將結果轉換爲JSON的MongoDB數據庫。
這是我的代碼如何將tweepy搜索的結果轉換爲JSON格式
import tweepy
import json
import pymongo
from pymongo import MongoClient
client=MongoClient()
db=client.scholarship
APP_KEY = app key here
APP_SECRET = app secret here
OAUTH_TOKEN = access-token here
OAUTH_TOKEN_SECRET = token secret here
auth=tweepy.OAuthHandler(APP_KEY,APP_SECRET)
auth.set_access_token(OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
api=tweepy.API(auth)
for tweet in tweepy.Cursor(api.search,q="scholarship",count=100,result_type="recent",include_entities=True,lang="en").items():
tweet=json.dumps(tweet)
try:
db.daily.insert(tweet)
except Exception as e:
print "there is a problem ",e
else:
print "inserted"
我得到一個錯誤
加薪類型錯誤(再版(O)+「是不是JSON序列化」)
的原因是檢索算法的返回類型是的形式
(貢獻者=無,截斷=假,文本= u'RT @AnwenAb:@OralRobertsU 2016的MedPro的Rx公司\ ufffdEducation就是力量\ ufffd獎學金申請截止日期2016' 年6月1日,is_quote_status = FALSE)
需要建議wha t可以在這裏完成。
謝謝!