У меня есть этот тест HTML страница
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> <html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="created" content="2020-05-29T11:12:00.0000000" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{659babcd-9de3-0e7a-27ba-7fa0325a40f7}{216}" style="position:absolute;left:72px;top:43px;width:696px">
<p id="p:{659babcd-9de3-0e7a-27ba-7fa0325a40f7}{218}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt"><span style="font-weight:bold">Test1###yrdy</span></p>
<p id="p:{659babcd-9de3-0e7a-27ba-7fa0325a40f7}{220}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test2###qweqwe</p>
<p id="p:{d59b11dc-654f-0d5c-0ee2-f66181a6fa4b}{22}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt"><span style="color:red">Test3</span> ###qweqeqwe</p>
<p id="p:{d59b11dc-654f-0d5c-0ee2-f66181a6fa4b}{17}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test4 ### sfsfsdfds</p>
<p id="p:{d59b11dc-654f-0d5c-0ee2-f66181a6fa4b}{19}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test5### 121212</p>
</div>
</body>
</html>
После превращения вышеуказанного в суп, я делаю это
for element in soup.find_all(["p"],text=re.compile("###")):
print(element)
В приведенном выше примере печатаются следующие
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> <p id="p:{659babcd-9de3-0e7a-27ba-7fa0325a40f7}{218}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt"><span style="font-weight:bold">Test1###yrdy</span></p>
<p id="p:{659babcd-9de3-0e7a-27ba-7fa0325a40f7}{220}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test2###qweqwe</p>
<p id="p:{d59b11dc-654f-0d5c-0ee2-f66181a6fa4b}{17}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test4 ### sfsfsdfds</p>
<p id="p:{d59b11dc-654f-0d5c-0ee2-f66181a6fa4b}{19}" lang="en-US" style="font-size:10.5pt;margin-top:0pt;margin-bottom:0pt">Test5### 121212</p>
Почему пропускается соответствующий p Test3?
Обновление:
Андрей, ваш предложение работает, но меня озадачивает, потому что поиск
soup.find_all (["p"], text = re.compile ("###")) должен иметь такой же эффект. Это
for p in soup.html.body.find_all("p"):
print(p.text)
Test1 ### yrdy
Test2 ### qweqwe
Test3 ### qweqeqwe
Test4 ### sfsfsdfds
Test5 ### 121212