matthew yap
matthew yap

Reputation: 1

I cant seem to extract a certain value from a website using beautiful soup

from bs4 import BeautifulSoup as soup

from urllib.request import urlopen as uReq

page = uReq ("https://www.binance.com/en")

data_1 = soup(page, 'html.parser')

a = data_1.body.div.main.find("div", class_="sc-bdVaJa bfHstm").table.find_all("div", class_="sc-bdVaJa dvJpRY")

print(a)

I am relatively new to beautiful soup, and i was trying to extract the price from binance website but i cant seem to select past the table to get to the price of bitcoin. Any help will be much appreciated. Thanks!

Upvotes: 0

Views: 60

Answers (1)

Hymns For Disco
Hymns For Disco

Reputation: 8405

You cannot extract this data from the page, because it's not actually part of the page that is returned when you request this url. All of the price data there is added in dynamically by javascript after the page is loaded. In order to extract this data from the page, you would need to first execute the javascript and then read those divs after they've actually been created, and BeautifulSoup is not meant to do this, and is not capable of it. It is only for analyzing static html/xml

If you want to query price listings from binance, you could use this python-binance package. This get_all_tickers function is probably what you're after

Returns: List of market tickers

[
    {
        "symbol": "LTCBTC",
        "price": "4.00000200"
    },
    {
        "symbol": "ETHBTC",
        "price": "0.07946600"
    }
]

Upvotes: 3

Related Questions