I am trying to download/scrape the exchange rate of DKK to USD from a website. I have managed to almost get there. But this code returns more than the floating point no that I need.
#!/usr/bin/env python
import urllib.request, urllib.error, urllib.parse
from bs4 import BeautifulSoup
url = "http://www.x-rates.com/table/"
page = urllib.request.urlopen(url)
soup_packtpage = BeautifulSoup(page)
page.close()
#First, we will search for the table with class="views-view-grid" as follows:
ratestable = soup_packtpage.find("table",class_="tablesorter ratesTable")
# Find and print the value of Danish Krone to USD - only the floating point no.
print(soup_packtpage.find(text="Danish Krone").findNext('td').contents[0])
But this code returns more than the floating point no that I need. it returns this mess:
<a href="/graph/?from=USD&to=DKK">7.019776</a>
Please can someone enlighten me as to how to strip the string from this floating point result, so I can store it as a variable?