Reputation: 91
I'm trying to get the current currency exchange rates. This is my script so far:
import requests
from bs4 import BeautifulSoup
# Collect and parse first page
page = requests.get('https://www.xe.com/currencyconverter/convert/?
Amount=1&From=GBP&To=USD')
soup = BeautifulSoup(page.text, 'lxml')
c_rate=soup.find(class_='converterresult-conversionTo')
however when i print(soup)
it pulls meta content and link href, I've played around with the parsers and the same problem happens with 'html.parser' aswell
Any ideas?, if you go on the page im trying to pull the 1.30451 figure out.
Thanks,
Upvotes: 2
Views: 112
Reputation: 24930
Selenium can help you do it:
from selenium import webdriver
from bs4 import BeautifulSoup
url = 'https://www.xe.com/currencyconverter/convert/?%20Amount=1&From=GBP&To=USD'
browser=webdriver.Firefox()
browser.get(url)
soup=BeautifulSoup(browser.page_source)
rate = soup.select("a[href*=https://www.xe.com/currencycharts/?from=GBP&to=]")[1]
print(rate.text)
Output:
1.30449
If you change [1]
, in the rate
variable to [2]
, [3]
or [4]
, you should the GPB exchange rates for EUR, INR and AUD, respectively.
Upvotes: 1