D
D
didrux2020-07-28 18:52:51
Python
didrux, 2020-07-28 18:52:51

How to pull information from api?

I was looking for a solution to my problem on the Internet, I found a link to habr Why does it not display by id with Beautiful Soup?
There, user Ranc58 gave an example, and wrote: "..As a result, you don't need to parse anything, just pull information from the API"

Question: how to pull information from the API?

There is such a url https://minfin.com.ua/api/currency/ratelist/?curre...
You need to extract information about the USD rate from it (by the sell parameter), so that you can execute print('smth') and get dollar exchange rate in one line

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-07-28
@didrux

There is a regular json.
Example:

import json
import requests

response = requests.get('https://minfin.com.ua/api/currency/ratelist/?currency1=usd&currency2=uah&converter_type=midbank')
json_data = json.loads(response.text)
sell = json_data['data']['rates']['sell']
for key in sell:
  print(key, '->', sell[key])

Result
USD -> 27.5000
UAH -> 1
RUB -> 0.3600
EUR -> 32.0000
PLN -> 6.8000
GBP -> 34.0000
CZK -> 1.0000
CNY -> 3.0000
BYN -> 12.5000
KZT -> 0

You can use the jsonviewer.stack.hu service to view the json structure.

D
Dimonchik, 2020-07-28
@dimonchik2013

gygy
this is not that API
with such an API no problems at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question