我可以在执行以下操作后将值 us_price
转换为整数吗:
import urllib.request
page = urllib.request.urlopen ("http://au.finance.yahoo.com/q?s=AUDUSD=X")
text = page.read().decode("utf8")
where1 = text.find('yfs_l10_audusd=x">')
start_of_us_price = where1 + 18
end_of_us_price = start_of_us_price + 6
us_price = text[start_of_us_price:end_of_us_price]
我已尝试usp = int(us_price)
但无济于事
最佳答案
您可能应该使用float(us_price)
,但如果您想要int,则int(float(us_price))
。
关于python - 将 urllib.request 转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686715/