Trying to make a soup.select for multiple cases

Viewed 49

today I'm scratching my head on this problem.

Basically I'm using this code:

    for link in soup.select(".lif__pricing"):
        list_prices.append(link.get_text(strip=True))

to find all the .lif__princing tags and get the price from them.

Here come my problem: I use the list to put it next to a column on titles related to the prices, but sometimes the prices are not listed and instead they use a tag .lif__pricing--wrapped and the list gets basically 1 row behind the titles list.

So to make you better understand what I can't for the life of me achieve, here is the logic code one would do:

    for link in soup.select(".lif__pricing" and ".lif__pricing--wrapped"):
        list_prices.append(link.get_text(strip=True))

How can I make this code, but that does't give me only the ones for .lif__pricing--wrapped...

Thanks for the answers!

1 Answers

To get tags with class "lif__pricing" and "lif__pricing--wrapped" use:

for link in soup.select(".lif__pricing, .lif__pricing--wrapped"):
    list_prices.append(link.get_text(strip=True))

For mode info, you can use CSS selector guide.

Related