我正在尝试从网站下载/抓取丹麦克朗兑美元的汇率。我已经设法几乎到达那里。但是这段代码返回的不仅仅是我需要的浮点数。
#!/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])
但是这段代码返回的不仅仅是我需要的浮点数。它返回这个烂摊子:
<a href="/graph/?from=USD&to=DKK">7.019776</a>
请有人告诉我如何从这个浮点结果中删除字符串,以便我可以将它存储为变量?