Search code examples
pythonbeautifulsoup

Get the data in the Span class of HTML by Python


I am trying to get the data in one of span class from a website. Currently, I caught the correct position of my data but I can't get the text of class.

My code:

import requests
from bs4 import BeautifulSoup

res = requests.get('https://coinmarketcap.com/currencies/chainlink/')

soup = BeautifulSoup(res.text, 'lxml')

elements = soup.find_all("span", class_="sc-f70bb44c-0 flfGQp flexStart alignBaseline")
values = soup.find_all("span", class_="sc-f70bb44c-0 jxpCgO base-text")
print(values)

My output: span class="sc-f70bb44c-0 jxpCgO base-text">$14.22</span

My expectation is get the only "$14.22"


Solution

  • Replace

    print(values)
    

    with

    for value in values:
        print(value.get_text())