0

I want to scrape this website and get the price from it. When I run my code I always get None, I have tried with .find and .find_all but the result is always the same:

from bs4 import BeautifulSoup
import requests

r = requests.get('https://finance.yahoo.com/quote/BTC-USD?p=BTC-USD')
soup = BeautifulSoup(r.text, 'xml')


stock_price = soup.find('span', class_='Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)')

# I should get 8,531.30
print(stock_price)

I see that 'span', class_='Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)' is dynamic, but then I have tried to get unique div thats above:

stock_price = soup.find_all('div', class_='D(ib) Va(m) Maw(65%) Ov(h)')

or:

stock_price = soup.find_all('div', class_='D(ib) Mend(20px)')

These 2 divs are not dynamic, only two spans inside them are dynamic, why cant I get my elements?

I have watched this tutorial and they do not use Chrome Selenium

https://www.youtube.com/watch?v=rONhdonaWUo

What am I doing wrong?

taga
  • 3,537
  • 13
  • 53
  • 119

1 Answers1

0
class="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)"

It is just dynamically generated clas by javascript so you need to get attached to another attribute or to another tag. Also, remember you this attribute must be unique on the page if not find() return just first coincidence

  • I have tried that, I have tried to get div thats above, but the result is the same – taga Nov 16 '19 at 11:29
  • I think every attribute where we have (px) is dynamic for different browsers, screen sizes etc, that means python gets this data in another view. You can look at how it looks in python just save the page into some file.. Also we can get div by id="quote-header-info" and try to parse it in deeper level – Yevhenii Avlasenko Nov 16 '19 at 14:06