I want to print the real price of bitcoins using python, but when extracting the name of the currency and its amount, I get an error of AttributeError: 'NoneType' object has no attribute 'text'
Here is the code I used:
from bs4 import BeautifulSoup as BS
import requests
url = "https://api.coinbase.com/v2/prices/ETH-CAD/buy"
data = requests.get(url)
soup = BS(data.text, 'html.parser')
ans = soup.find("amount", class_="currency").text
in the last line, it gives me an error of AttributeError: 'NoneType' object has no attribute 'text'
How can I solve that issue?
CodePudding user response:
Have you ever downloaded that page and looked at it yourself? It doesn't return HTML at all. It returns JSON. You don't need BeautifulSoup.