Python Regex将从div中删除所有内容 html= 发送 通过 使用 .

Python Regex将从div中删除所有内容 html= 发送 通过 使用 . ,python,regex,Python,Regex,我有这个正则表达式 html = <div> <p style="color: #555555; margin-top:32px;"> Sent <span> by <a style="text-decoration:none; color: #875A7B;" href="http://www.example.com"> <span>Y

我有这个正则表达式

html = 
<div>
<p style="color: #555555; margin-top:32px;">
    Sent
   <span>
    by
    <a style="text-decoration:none; color: #875A7B;" href="http://www.example.com">
    <span>YourCompany</span>
   </a>

</span>
    using
  <a target="_blank" href="https://www.odoo.com?utm_source=db&amp;utm_medium=email" 
        style="text-decoration:none; color: #875A7B;">Odoo</a>.
      </p>
html=re.sub(
'使用'+''(.*)[\r\n]*(.*)>“+'Odoo'+r”“”,html,
)
我得到了结果

html = re.sub(
            'using' + "(.*)[\r\n]*(.*)>" + 'Odoo' + r"</a>", "", html,
        )
html=

发送 通过 .


但是如何更新我的正则表达式以从更新中删除所有内容 使用相同的模式,您可以首先检查
是否包含
“Sent”
“by”


pattern=re.compile(“我更新了我的问题,还有一个问题clause@Chaban33更新了我的答案:)实际上,您的代码给出了这个错误TypeError:re.Match类型的参数不是iterable@Chaban33我无法重现此错误。此外,我没有迭代任何
匹配
对象,因此我不认为错误来自我的代码。您可以使用有关错误及其发生位置的更多信息更新您的问题,以便我可以查看它。考虑使用解析器(例如<代码> BeautifulSoup < /代码>)和<代码> XPath < /代码>查询代替。
html =
<div> 
<p style="color: #555555; margin-top:32px;">
Sent
<span>
by
<a style="text-decoration:none; color: #875A7B;" href="http://www.example.com">
    <span>YourCompany</span>
</a>

</span>
.
</p>
  </div>