S
S
StrangeDylan2021-05-07 16:16:01
Python
StrangeDylan, 2021-05-07 16:16:01

Why is None returned when parsing?

You need to parse the bitcoin rate in real time. When the code is executed, None is returned, although there is such a class on the page and it is loaded immediately.

import requests
from bs4 import BeautifulSoup

url = 'https://www.tradingview.com/symbols/BTCUSD/?utm_campaign=tickers&utm_medium=widget&utm_source=xn----dtbfdbwspgnceulm.xn--p1ai'

HEADERS = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36 OPR/75.0.3969.259'}

source_code = requests.get(url, headers=HEADERS)
soup = BeautifulSoup(source_code.text, 'html.parser')
bitcoin_curse = soup.find('label', {'class': 'tab-HYHP1WHx tabSelected-HYHP1WHx'})
print(bitcoin_curse)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-05-07
@SoreMix

although there is such a class on the page and it is loaded immediately

6095400058977915213790.jpeg
It's not there. Even visually it is clear that it does not immediately appear. Data comes via wss
wss://data.tradingview.com/socket.io/websocket?from=symbols%2FBTCUSD%2F&date=2021_05_06-10_12

Once tradingview was parsed by order, it was possible to receive currencies through https://scanner.tradingview.com/crypto/scan of BINANCE :BTCUSDT and BINANCE:BTCRUB pairs . I have no idea how things are going there now, but it's better to look for another site for the course

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question