简体   繁体   English

如何从键值中获取并从该值中获取另一个值

[英]How to take from key value and take from this value another value

How can i get needed value, because i send post request to other site and cant edit answer from site.我如何获得所需的价值,因为我将发布请求发送到其他站点并且无法编辑站点的答案。

I have this dict from responded content:我从响应内容中得到了这个 dict:

{'username': 'DeadFinder', 'subscriptions': [{'subscription': 'default', 'expiry': '1635683460'}], 'ip': 'not at this life'}

How you can see in this dict there is a key subscriptions , i'm need value expiry (this is timestamp) but how can i get this value if when i'm trying to call this value i'm not see any results (code not gives needed value), maybe any variants how to get this value?您如何在此字典中看到有一个关键subscriptions ,我需要值expiry (这是时间戳)但是如果当我尝试调用此值时我没有看到任何结果(代码),我如何获得此值没有给出所需的价值),也许有任何变体如何获得这个价值? I'm not finded anything like this.我没有找到这样的东西。

Maybe my small part of code can smally help you but i doubt.也许我的一小部分代码可以帮助你,但我怀疑。

    data1 = {f"hwid":"", "type":"login", "username": {username}, "pass": {password}, 
    "sessionid":f"{response_cut2}", "name":"test_app", "ownerid":"5OLbm5S3fS"}
    url1 = "nope"
    response1 = requests.post(url1, data1)
    data = response1.json()
    #get = data.get('expiry')
    file_write = open("test.txt", "w")
    file_write.write(str(data))
    file_write.close()
    for key in data.keys():
      if key == 'info':
        print (data[key])

Are you trying to achieve this as result ?您是否正在努力实现这一目标?

data = {'username': 'DeadFinder', 'subscriptions': [{'subscription': 'default', 'expiry': '1635683460'}], 'ip': 'not at this life'}
print(data['subscriptions'][0]['expiry'])


# first get 'subscriptions' which returns an array, 
# so use [0] to get this dict {'subscription': 'default', 'expiry': '1635683460'}
# then get 'expiry'

EDIT : In case subscriptions has multiple values then use for loop编辑:如果订阅有多个值,则使用 for 循环

subscriptions = data['subscriptions']
for subscription in subscriptions:
    print(subscription['expiry'])

Output输出

1635683460

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM