Парсинг по определенным тегам "class"

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup as BS

opts = Options()
opts.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36")
caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "eager"  #  interactive
driver = webdriver.Chrome(desired_capabilities=caps, options=opts, executable_path=r'C:\Users\chromedriver.exe')
driver.get("https://www.marathonbet.ru/su/betting/Basketball+-+6?interval=H24")



requiredHtml = driver.page_source
soup = BS(requiredHtml, 'html.parser')
#print(soup)
indexes=soup.find_all('td', {'class':['selection-link']})
ree = {}
for x in indexes:
   ree[x.findNext('span').text]=x#.findNext('a').get('href')

for a, b in ree.items(): print(a, b)
driver.close()

Нужная часть текста :

<span class="selection-link
active-selection 
" data-selection-price="1.33" data-prt="CP" data-selection-key="9244974@Match_Winner_Including_All_OT.HB_H">1.33</span>
    </td>
     <td colspan="1" class="price height-column-with-price    coupone-width-1" data-coeff-uuid="97162486-61300330927" data-sel="{&quot;sn&quot;:&quot;Ховентуд&quot;,&quot;mn&quot;:&quot;Победитель матча, включая все ОТ&quot;,&quot;ewc&quot;:&quot;1/1 1&quot;,&quot;cid&quot;:61300330927,&quot;prt&quot;:&quot;CP&quot;,&quot;ewf&quot;:&quot;1.0&quot;,&quot;epr&quot;:&quot;3.98&quot;,&quot;prices&quot;:{&quot;0&quot;:&quot;149/50&quot;,&quot;1&quot;:&quot;3.98&quot;,&quot;2&quot;:&quot;+298&quot;,&quot;3&quot;:&quot;2.98&quot;,&quot;4&quot;:&quot;-0.336&quot;,&quot;5&quot;:&quot;2.98&quot;}}" data-mutable-id="S1548679762" data-market-type="RESULT_2WAY">

       <span class="selection-link

Ответы (1 шт):

Автор решения: Linkeln

В чем смысл такого трудно читаемого ,длинного парсера? Можно все сделать в разы проще...

elem = browser.find_elements_by_xpath("//*[@title]") # или любое тебе нужное значиние,к примеру class
elems = browser.find_elements_by_xpath("//a[@title]")
for elem in elems[0:1]:
    cc = (elem.get_attribute("title")) # вписываешь везде вместо title нужное тебе значние... И все должно сработать
→ Ссылка