I\'m having trouble parsing HTML elements with \"class\" attribute using Beautifulsoup. The code looks like this
soup = BeautifulSoup(sdata)
mydivs = soup.fi
CSS selectors
single class first match
soup.select_one('.stylelistrow')
list of matches
soup.select('.stylelistrow')
compound class (i.e. AND another class)
soup.select_one('.stylelistrow.otherclassname')
soup.select('.stylelistrow.otherclassname')
Spaces in compound class names e.g. class = stylelistrow otherclassname
are replaced with ".". You can continue to add classes.
list of classes (OR - match whichever present
soup.select_one('.stylelistrow, .otherclassname')
soup.select('.stylelistrow, .otherclassname')
bs4 4.7.1 +
Specific class whose innerText
contains a string
soup.select_one('.stylelistrow:contains("some string")')
soup.select('.stylelistrow:contains("some string")')
Specific class which has a certain child element e.g. a
tag
soup.select_one('.stylelistrow:has(a)')
soup.select('.stylelistrow:has(a)')