Find partial class names in spans with Beautiful Soup

后端 未结 2 1716
囚心锁ツ
囚心锁ツ 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})
      

提交回复
热议问题