Beautiful findall soup multiple classes using a single query

I carefully searched for a solution on many sites here, but none of them work!

I am trying to clear flashscores.com and I want to parse <td>with a class name cell_ab team-homeorcell_ab team-home bold

I tried to use re

soup.find_all('td', { 'class'= re.compile(r"^(cell_ab team-home |cell_ab team-home  bold )$"))

and

soup.find_all('td', { 'class' : ['cell_ab team-home ','cell_ab team-home  bold '])

none of them work.

someone requested codes, so here

 from tkinter import *
 from selenium import webdriver
 import threading
 from bs4 import BeautifulSoup

 browser = webdriver.Firefox()
 browser.get('http://www.flashscore.com/')

 HTML = browser.page_source
 soap = BeautifulSoup(HTML)
 for item in soap.find_all('td', class_ = ['cell_ab team-home ','cell_ab team-home  bold ']):
        Listbox.insert(END,item.text)
+4
source share
4 answers

bs4The documentation says the following about mapping using class_:

Remember that a single tag can have multiple values ​​for its attribute class. When you search for a tag that matches a specific CSS class, you are matched against any of its CSS classes.


CSS , .select. , - :

soup.select('td.cell_ab.team-home')

<td>, cell_ab, team-home, <td>, , bold.

+2

re, :

soap.findAll('td', {'class' : re.compile('cell_ab team-home '|'cell_ab team-home  bold ')})

td class='cell_ab team-home' td clas='cell_ab team-home bold'

0

you can use sitax list, for example:

soup.findAll('td', {'class':['cell_ab team-home', 'cell_ab team-home  bold ']})
0
source

you can use the selector as follows:

soup.select('.cell_ab.team-home')
-1
source

All Articles