Beautiful Soup if Class “Contains” or Regex?

BeautifulSoup supports CSS selectors which allow you to select elements based on the content of particular attributes. This includes the selector *= for contains.

The following will return all div elements with a class attribute containing the text ‘listing-col-‘:

for EachPart in soup.select('div[class*="listing-col-"]'):
    print EachPart.get_text()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)