Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error in printing the real price and currency "AttributeError: 'NoneType' object has no attribute 'text'"

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading