Solution 1 :

Perhaps avoid dynamic classes an look for more stable elements, and if necessary, use the relationship between those to target that node:

import requests
from bs4 import BeautifulSoup as bs

r = requests.get('https://finance.yahoo.com/quote/WRD.PA?p=WRD.PA&.tsrc=fin-srch', headers = {'User-Agent':'Mozilla/5.0'})
soup = bs(r.content, 'lxml')
print(soup.select_one('div:has(> #quote-market-notice) > span').text)

Solution 2 :

You can do this without BeautifulSoup if you want:

from selenium import webdriver

driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get('https://finance.yahoo.com/quote/WRD.PA?p=WRD.PA&.tsrc=fin-srch')
element = driver.find_element_by_class_name("Fz(36px)")
print(element.text)

Problem :

I am trying to get value 26.70 from this span tag:

<span class="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)" data-reactid="31">26.70</span>

I tried this:

html_text2=requests.get('https://finance.yahoo.com/quote/WRD.PA?p=WRD.PA&.tsrc=fin-srch').text
soup2 = BeautifulSoup(html_text2,'lxml')
data = soup2.select_one('span.Fz(36px)').text.strip()
print(data)

but I am getting this error:

soupsieve.util.SelectorSyntaxError: Invalid character '(' position 7
  line 1:
span.Fz(36px)
       ^

Comments

Comment posted by Jeremy Savage

It looks like your error is in line 1 which is not included here…

Comment posted by Leonard

Try escaping the parentheses:

By