Find partial class names in spans with Beautiful Soup

后端 未结 2 1698
囚心锁ツ
囚心锁ツ 2020-12-21 19:06

This page https://www.kijiji.ca/v-1-bedroom-apartments-condos/ville-de-montreal/1-chambre-chauff-eau-chaude-incl-vsl-514-856-0038/1334431659 contains this span class:

<
相关标签:
2条回答
  • 2020-12-21 19:21

    According to the docs you have several options:

    • Use a regex:

      soup.find_all('span', attrs={'class': re.compile('^currentPrice.*')})
      
    • Use a function:

      soup.find_all('span',
                    attrs={'class': lambda e: e.startswith('currentPrice') if e else False})
      
    0 讨论(0)
  • 2020-12-21 19:27

    You could try a CSS selector soup.select('span[class*="currentPrice-"]')

    0 讨论(0)
提交回复
热议问题