How to obtain currency rates from this website converter widget python

2024/10/15 5:19:29

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.

This is the website

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 scraping is not as straightforward.

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

Answer

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 jsonurl = "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.

https://en.xdnf.cn/q/117866.html

Related Q&A

Trying to add sums from a csv file in python

I need to add sums of a csv file. The program is a test for a travel reservation system and the file reads like this:availableSTART,reservations,cancellations,availableEND 20,1,0,18I need to subtract r…

Numerical patterns in Python3 [duplicate]

This question already has answers here:How to print without a newline or space(30 answers)Closed 7 years ago.Im fairly new to programming, i have to start learning it for Uni.I have to make a pattern a…

setsockopt before connect for reactor.connectTCP

I have a small python client which needs a setsockopt after create_socket, but before connect. The non-twisted python code is as follows. How can this be expressed in a twisted environment?create_sock…

Manage quotation marks in XPath (lxml)

I want to extract web elements from the table MANUFACTURING AT A GLANCE in the given website. But the name of the row has (single quote). This is interfering with my syntax. How do I overcome this iss…

exception capture in threads and parent

How do you nicely capture exceptions in Python threads?If you have a threaded python app sys.excepthook does not capture errors in children.When a child raises an exception the parent will continue to…

Writing a program that compares 2 numbers in Python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Run Python3 without activating the virtual environment

My objective is to run Python 3 code on the AWS Lambda Service, which currently only supports Python 2.7. These are the steps I have done.Since I work on a Mac, setup a docker image similar to the AWS …

Matplotlib functions in tkinter

This is my first python project so I understand that this problem may seem a bit stupid. I am trying to create a Mandelbrot renderer. I am piecing code together from tutorials and code that I understan…

sudo su user -c with arguments not working

I am trying to execute command from python as another "user" with:command = "sudo su user -c player --standard=1 -o 2" subprocess.Popen(command.split(), shell=False, stdin=None, std…

Grouping data on column value

Hi I have data (in excel and text file as well) like C1 C2 C31 p a1 q b2 r c2 s dAnd I want the output like:C1 C2 C31 p,q a,b2 r,s c,dHow can I group the data…