The US Federal Reserve has information on exchange rates, for example Sterling to US Dollars: https://www.federalreserve.gov/releases/h10/hist/dat00_uk.htm
Note that the direction of the exchange is not constant for all currencies.
Examining the structure of the web page showed the table containing the data is identified by it having a class of "pubtables".
LXML is used to take the table data and allow it to be searched using XPATH.
The program outputs the data as a CSV file.
# Function to extract exchange rates from US Federal Reservefrom lxml import htmlimport requestsimport collectionsimport csvfrom datetime import datetimeurl= "https://www.federalreserve.gov/releases/h10/hist/dat00_uk.htm"def get_US_exchange_rates(aURL):exchangerates=collections.OrderedDict()# Get the page from the URLprint("Get page")page = requests.get(aURL)# Make an HTML tree from the textprint("Make HTML page")tree = html.fromstring(page.content)# The data is in a table of class="pubtables"r=tree.xpath("//table[@class='pubtables']/tr")print("Iterate over xpath")for x in r:if x[1].text_content().strip()!="ND":exchangerates[datetime.strptime(x[0].text_content().strip(),"%d-%b-%y")]=float(x[1].text_content().strip() )print("Done")return exchangerates# Testing codeif __name__ == "__main__":print ('Exchange Rates:')if True:c=get_US_exchange_rates(url)with open('exchange.csv', 'w') as csvfile:exchwriter=csv.writer(csvfile,delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)for x in c:print(x,c[x])exchwriter.writerow([x,c[x]])