st1= str()
c1= str()
c2= str()
EndCash = float()
page = requests.get('http://www.xe.com/currencyconverter/convert/?Amount=' +
str(st1) + '&From=' + (c1) + '&To=' + (c2))
tree = html.fromstring(page.content)
rate = tree.xpath('//span[@class="uccResultAmount"]/text()')
symbol = tree.xpath('//span[@class="uccToCurrencyCode"]/text()')
EndCash = rate + symbol
我使用requests
模块和lxml
从互联网上获取汇率。我在做这件事时遇到了问题。我收到一个must be str, not float
错误。我将这行代码用于tkinter
中的一个标签,因此EndCash
的输出应该出现在标签中。此代码独立工作,但在tkinter
中它不工作
在第一个国家。在
像这样你的代码应该可以工作,你必须在定义浮动之后将它们转换成字符串
相关问题 更多 >
编程相关推荐