pymongoを使用してmongodbに接続しています:
client = MongoClient()
mongo = MongoClient('localhost', 27017)
mongo_db = mongo['test']
mongo_coll = mongo_db['test'] #Tweets database
私はカーソルを持っていて、すべてのレコードをループしています:
cursor = mongo_coll.find()
for record in cursor: #for all the tweets in the database
try:
msgurl = record["entities"]["urls"] #look for URLs in the tweets
except:
continue
の理由は、存在しないtry/except
場合はエラーになるためです。["entities"]["urls"]
存在するかどうかをどのように判断でき["entities"]["urls"]
ますか?