Can we combine '[class="a"]' and '[id="c d"]' in the same command?
09:01 25 May 2025

I have a html where I want to get elements with class="a" and id="c d". If I have only one of them, I can use soup.select('[class="a"]') and soup.select('[id="c d"]').

Can we combine '[class="a"]' and '[id="c d"]' in the same command?

from bs4 import BeautifulSoup

# Example HTML
html = """
    Content 1
  • python beautifulsoup css-selectors html-parsing