Home > database >  how can i select part of this text
how can i select part of this text

Time:09-10

hello so i am trying to print only the [code] here but i couldn't

import requests

token = 'token'

id = "35633560231"
headers = {
    'Authorization': 'Bearer '   token,
    'Accept': 'application/json',
}

response = requests.get('https://5sim.net/v1/user/check/'   id, headers=headers)
datas = response.json()
smss = datas['sms']
print(smss)

sms print : [{'created_at': '2022-09-09T14:25:01.486075Z', 'date': '2022-09-09T14:25:01.481586Z',      'sender':   'Amazon', 'text': "625172 is your Amazon OTP. Don't share it with anyone.", 'code': '625172'}]

i want to get the code value only i tried smss = smss['code'] but it didn't work

CodePudding user response:

data['sms'] is a list and you have the json object at index 0. This should work:

sms=[{'created_at': '2022-09-09T14:25:01.486075Z', 'date': '2022-09-09T14:25:01.481586Z',      'sender':   'Amazon', 'text': "625172 is your Amazon OTP. Don't share it with anyone.", 'code': '625172'}]
print(f"Code: {sms[0]['code']}")

output:

Code: 625172
  • Related