如何从此网站转换器小部件python获取货币汇率 [英] How to obtain currency rates from this website converter widget python

查看:145
本文介绍了如何从此网站转换器小部件python获取货币汇率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在该网站上实施货币汇率并保持货币最新,以便我可以从该网站以python格式访问它们以及输入和输出值以及货币类型.我需要我的程序才能连接到此页面,并使用该页面上的货币转换器应用程序获取货币汇率.

How can I implement the currency rates on this website and keep the currencies up to date so that i can access them in python from this website and input and output values and currencies types. I need my program to connect to this webpage and take the rates of the currency using the currency converter app on the webpage.

这是网站

我需要知道如何在许多有网站的大街货币供应商处执行此操作,但是许多供应商没有提供汇率列表,因此网络抓取并不是那么简单.

I need to know how to do this on many high street currency providers that have a website however many do not supply a list of rates so web scrapping is not as straightforward.

我需要使用pip安装哪些模块,以及如何使用它们来实现我的目标. 非常感谢

Which modules will i need to install using pip and how will i be able to use them to achieve my goal. Many thanks

推荐答案

您可以使用以下代码,其中exchange_rates是将货币映射到其汇率的字典(URL是

You can use the following code where exchange_rates is a dict mapping currencies to their rates (the url is the one that this page uses to load it's data)

import requests
import json

url = "https://api.travelex.net/salt/config/multi?key=Travelex&site=%2Fvirgin&options=abhikzl"
r = requests.get(url)
data = json.loads(r.text)
exchange_rates = data['rates']['rates']

for item in exchange_rates:
    print("{}, {}".format(item, exchange_rates[item]))

您可以通过将

You can apply this to most sites by loading them with the chrome developer network window open and look through the requests to find the one that loads in this data.

这篇关于如何从此网站转换器小部件python获取货币汇率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆