我正在嘗試創建一個簡單的腳本,向我顯示BRL x USD之間的貨幣值,我到達了獲取值的部分,但不是我需要的浮動變量用於未來的轉換操作。只能從變量中獲取數字
如何獲得brlxusd
變量中的數字?現在它打印出「0.253059美元」,我只想要「0.253059」部分。
import urllib
from bs4 import BeautifulSoup
def currencyValues():
url = urllib.urlopen('http://www.x-rates.com/calculator/?from=BRL&to=USD&amount=1')
soup = BeautifulSoup(url, "html.parser")
for usdbrl in soup.find_all("span", class_="ccOutputRslt"):
brlxusd = usdbrl.text
print "BRL x USD rate today: %s" % brlxusd
currencyValues()
沒想到這麼簡單的解決方案,效果很棒! Ty –
@DaviMartins歡呼!把事情簡單化。 –
您不需要傳遞分隔符來分割。 –