Search code examples
pythonweb-scrapingbeautifulsoupcryptocurrency

Web scraping with beautifulsoup not finding anything


I'm trying to scrape coinmarketcap.com just to get an update of a certain currency price, also just to learn how to web scrape. I'm still a beginner and can't figure out where I'm going wrong, because whenever I try to run it, it just tells me there are none. Although I know that line does exist. Any help is appreciated!

import requests
from bs4 import BeautifulSoup

url = 'https://coinmarketcap.com/currencies/electroneum/'
response = requests.get(url)
html = response.content

soup = BeautifulSoup(html, 'html.parser')
price = soup.find('data-currency-price data-usd=')
print (price)


Solution

  • You can use the class attribute to get the value.

    import requests
    from bs4 import BeautifulSoup
    
    url = 'https://coinmarketcap.com/currencies/electroneum/'
    response = requests.get(url)
    html = response.content
    
    soup = BeautifulSoup(html, 'html.parser')
    price = soup.find('span' ,attrs={"class" : "h2 text-semi-bold details-panel-item--price__value"})
    print (price.text)
    

    Output :

    0.006778