Python-从JSON获取页面ID
在Linux(Python)中:Python-从JSON获取页面ID,python,json,Python,Json,在Linux(Python)中: >>数据['query']['pages'] 据英国《68301{u'68301’:{u'提取:u'提取:u'
>>数据['query']['pages']
据英国《68301{u'68301’:{u'提取:u'提取:u'',u'ns':0,u'pageid':68301,u'title':u'Hijab'}
谁能帮我取那个号码(68301)这个号码是字典里的一个键:
>>> data['query']['pages']
{u'68301': {u'extract': u'<p/>"</b>Hijab</b>" or "</b>\u1e25ij\u0101b</b>" (/h\u026a\u02c8d\u0292\u0251\u02d0b/, /h\u026a\u02c8d\u0292\xe6b/, /\u02c8h\u026a.d\u0292\xe6b/ or /h\u025b\u02c8d\u0292\u0251\u02d0b/;Arabic: \u062d\u062c\u0627\u0628\u200e, <small>pronounced </small>[\u0127i\u02c8d\u0292\xe6\u02d0b] ~ [\u0127i\u02c8\u0261\xe6\u02d0b]) is a veil which covers the head which is particularly worn by Muslim women beyond the age of puberty in the presence of non-related adult males.</p>', u'ns': 0, u'pageid': 68301, u'title': u'Hijab'}}
.keys()
返回字典键列表,有关字典的完整API,请参阅。数字是字典中的一个键:
>>> data['query']['pages']
{u'68301': {u'extract': u'<p/>"</b>Hijab</b>" or "</b>\u1e25ij\u0101b</b>" (/h\u026a\u02c8d\u0292\u0251\u02d0b/, /h\u026a\u02c8d\u0292\xe6b/, /\u02c8h\u026a.d\u0292\xe6b/ or /h\u025b\u02c8d\u0292\u0251\u02d0b/;Arabic: \u062d\u062c\u0627\u0628\u200e, <small>pronounced </small>[\u0127i\u02c8d\u0292\xe6\u02d0b] ~ [\u0127i\u02c8\u0261\xe6\u02d0b]) is a veil which covers the head which is particularly worn by Muslim women beyond the age of puberty in the presence of non-related adult males.</p>', u'ns': 0, u'pageid': 68301, u'title': u'Hijab'}}
.keys()
返回字典键列表,有关字典的完整API,请参阅。由于这是一个字典,您可以使用keys
函数:
>>> data['query']['pages'].keys()
[u'68301']
由于这是一个字典,您可以使用
键
功能:
>>> data['query']['pages'].keys()
[u'68301']
是
data['query']['pages']
adict
还是str
?@tcaswell:那绝对是dict
;python解释器中的表示没有引号。@MartijnPieters谢谢,这是我以前从未注意到的细节。是data['query']['pages']
adict
或str
?@tcaswell:那肯定是dict
;python解释器中的表示没有引号。@MartijnPieters谢谢,这是我以前从未注意到的细节。