import re from bs4 import BeautifulSoup html_doc = """ <p class="title">The Dormouse's story</p> <p class="story two">two</p> <p class="story">one</p> """ soup = BeautifulSoup(html_doc, 'html.parser') print(soup.find('p', {'class':re.compile('^story$')}).text)
I want to get "one" but get "two". Please tell me where the error.
stackoverflow.com/questions/37897087/beautifulsoup-regex-not-working
html_doc = """ <p class="title">The Dormouse's story</p> <p class="story two">two</p> <p class="story">one</p> """
[...]
print(soup.find('p', {'class':re.compile('^story$')}).text)