如何在tweepy api.get_用户方法(python)中获取实体内的值
这是我的密码如何在tweepy api.get_用户方法(python)中获取实体内的值,python,twitter,tweepy,Python,Twitter,Tweepy,这是我的密码 consumerKey=" " consumerSecret=" " accessToken=" " accessSecret=" " auth = tweepy.OAuthHandler(consumerKey, consumerSecret) auth.set_access_token(accessToken,accessSecret) api = tweepy.API(auth) customerinfo = api.get_user('@ABC') print "en
consumerKey=" "
consumerSecret=" "
accessToken=" "
accessSecret=" "
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken,accessSecret)
api = tweepy.API(auth)
customerinfo = api.get_user('@ABC')
print "entities :",customerinfo.entities
输出:
entities : {u'description': {u'urls': [{u'url': u'https:/t.co/fdsfdsdsff',
u'indices': [56, 79], u'expanded_url': u'http:/www.facebook.com/fsdfds',
u'display_url': u'facebook.com/dfsfds'}, {u'url': u'https:/t.co/dfdsfdsfds',
u'indices': [82, 105], u'expanded_url': u'http:/www.instagram.com/fsdfsdfds',
u'display_url': u'instagram.com/dfdsfdsfds'}]}}
如何将URL值获取到变量
我尝试了customerinfo.entities.description和customerinfo.entities.url
但它不起作用。它不起作用,因为变量“entities”是“dictionary”类型。请看:部分:5.8。映射类型-dict。您需要通过“key”值获得访问权限,如下所示:
customerinfo.entities['description']
customerinfo.entities['description']['urls']
等等。在提问之前检查文档通常是一个很好的做法。这不起作用,因为变量“entities”是“dictionary”类型。请看:部分:5.8。映射类型-dict。您需要通过“key”值获得访问权限,如下所示:
customerinfo.entities['description']
customerinfo.entities['description']['urls']
等等。在提问之前检查文档通常是一种很好的做法。
customerinfo实体
属于dict
类型。使用键名访问字典中的值有两种方法:
方法a)。如果不存在这样的密钥,将返回KeyError
。
方法b)。如果不存在这样的键,将返回None
。
因此,方法b)。当您没有确认字典中存在键时,更可取。
customerinfo实体
属于dict
类型。有两种方法可以使用键名访问字典中的值:
方法a)。如果不存在这样的密钥,将返回KeyError
。
方法b)。如果不存在这样的键,将返回None
。
因此,方法b)。当您没有确认字典中存在键时,更可取。实体似乎是字典;您是否尝试过通过键访问其内容?您得到的错误消息是什么(“不起作用”非常少)?你读过图书馆文档吗?我对tweepy和python还不熟悉,你能给我发一个图书馆文档的链接吗……你对谷歌搜索还不熟悉吗?得到了一份文件,看来是一本字典;您是否尝试过通过键访问其内容?您得到的错误消息是什么(“不起作用”非常少)?你读过图书馆文档吗?我对tweepy和python还不熟悉,你能给我发一个图书馆文档的链接吗……你对谷歌搜索还不熟悉吗?得到了ThnksTnku@Karol Thnku医生的建议。:)Tnku@Karol Thnku,以获取建议。:)