import hashlib
import requests
def privat_bank():
url = "https://api.privatbank.ua/p24api/rest_fiz"
password = "апрваравпрвапрвапр"
head = """<?xml version="1.0" encoding="UTF-8"?>
<request version="1.0">
<merchant>
<id>00000</id>
<signature>"""
data = """<oper>cmt</oper>
<wait>0</wait>
<test>0</test>
<payment id="">
<prop name="sd" value="5.05.2020" />
<prop name="ed" value="17.06.2020" />
<prop name="card" value="012345678910" />
</payment>"""
end_head = """</signature>
</merchant>
<data>
"""
footer = """
</data>
</request>"""
signature_md5 = hashlib.md5((data+password).encode('utf-8')).hexdigest()
signature_done = hashlib.sha1(signature_md5.encode('utf-8')).hexdigest()
data_done = head + signature_done + end_head + data + footer
res = requests.post(url, data=data_done, headers={'Content-Type': 'application/xml; charset=UTF-8'})
print(res.text)
def main():
privat_bank()
main()
Вот есть ответ:
<?xml version="1.0" encoding="UTF-8"?><response version="1.0"><merchant><id>000000</id><signature>5d7fcffa2290b7ed4ad98ff259d6b79420f01ce5</signature></merchant><data><oper>cmt</oper><info><statements status="excellent" credit="0.0" debet="107.0">
<statement card="012345678910" appcode="00000" trandate="2020-05-15" trantime="13:14:00" amount="92.00 UAH" cardamount="-92.00 UAH" rest="4363.19 UAH" terminal="LIQPAY*Privat24 Androi, I0110UWI" description="Пополнение мобильного +380970000000"/>
<statement card="012345678910" appcode="0000" trandate="2020-05-10" trantime="00:02:00" amount="15.00 UAH" cardamount="-15.00 UAH" rest="4455.19 UAH" terminal="PrivatBank, C400" description="Перевод на карту ПриватБанка через приложение Приват24. Получатель: Іванов Іван Іванович"/>
</statements></info></data></response>
Как из него вытянуть в переменную, rest или description?