我想在这个网站上获得btc价格。
from bs4 import BeautifulSoup
url = "https://koinim.com"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
g_data = soup.find_all(attrs={"nav-BTC-price"})
print(g_data)
结果是:
[<strong class="nav-BTC-price">10002.99</strong>]
Process finished with exit code 0
ı只想拿BTC价格(10002.99)。
TY
答案 0 :(得分:2)
使用 text 属性:
[g.text for g in g_data]
# ['10049.00']