python - 将 urllib.request 转换为整数

标签 python int urllib

我可以在执行以下操作后将值 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/

相关文章:

python - 为什么 python 打包文档说包的 __init__.py 文件应该是空的?

python - 如何将字符串输入元组?

python - Python3.6 的 virtualenv 上没有名为 '_sqlite3' 的模块

Java - 将数字分成三部分

python - 从 ftp 下载第二个文件失败

带有 urllib 的 Python 线程

python - 在网络服务器之外运行 python 脚本

java - 故意失去精度

swift - Float 到 Int 转换 Swift

python - requests 函数到底是做什么的?