Парсинг по определенным тегам "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="{"sn":"Ховентуд","mn":"Победитель матча, включая все ОТ","ewc":"1/1 1","cid":61300330927,"prt":"CP","ewf":"1.0","epr":"3.98","prices":{"0":"149/50","1":"3.98","2":"+298","3":"2.98","4":"-0.336","5":"2.98"}}" 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 нужное тебе значние... И все должно сработать