• <small id='IQ630'></small><noframes id='IQ630'>

      <legend id='IQ630'><style id='IQ630'><dir id='IQ630'><q id='IQ630'></q></dir></style></legend>
        <bdo id='IQ630'></bdo><ul id='IQ630'></ul>

      <i id='IQ630'><tr id='IQ630'><dt id='IQ630'><q id='IQ630'><span id='IQ630'><b id='IQ630'><form id='IQ630'><ins id='IQ630'></ins><ul id='IQ630'></ul><sub id='IQ630'></sub></form><legend id='IQ630'></legend><bdo id='IQ630'><pre id='IQ630'><center id='IQ630'></center></pre></bdo></b><th id='IQ630'></th></span></q></dt></tr></i><div id='IQ630'><tfoot id='IQ630'></tfoot><dl id='IQ630'><fieldset id='IQ630'></fieldset></dl></div>

      1. <tfoot id='IQ630'></tfoot>
      2. replaceWith() 后的 find() 不起作用(使用 BeautifulSoup)

        时间:2023-08-30
      3. <i id='sBTid'><tr id='sBTid'><dt id='sBTid'><q id='sBTid'><span id='sBTid'><b id='sBTid'><form id='sBTid'><ins id='sBTid'></ins><ul id='sBTid'></ul><sub id='sBTid'></sub></form><legend id='sBTid'></legend><bdo id='sBTid'><pre id='sBTid'><center id='sBTid'></center></pre></bdo></b><th id='sBTid'></th></span></q></dt></tr></i><div id='sBTid'><tfoot id='sBTid'></tfoot><dl id='sBTid'><fieldset id='sBTid'></fieldset></dl></div>
          <tbody id='sBTid'></tbody>

        <small id='sBTid'></small><noframes id='sBTid'>

          <tfoot id='sBTid'></tfoot>
              <bdo id='sBTid'></bdo><ul id='sBTid'></ul>
              <legend id='sBTid'><style id='sBTid'><dir id='sBTid'><q id='sBTid'></q></dir></style></legend>
                • 本文介绍了replaceWith() 后的 find() 不起作用(使用 BeautifulSoup)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  请考虑以下 python 会话:

                  Please consider the following python session:

                  >>> from BeautifulSoup import BeautifulSoup
                  >>> s = BeautifulSoup("<p>This <i>is</i> a <i>test</i>.</p>"); myi = s.find("i")
                  >>> myi.replaceWith(BeautifulSoup("was"))
                  >>> s.find("i")
                  >>> s = BeautifulSoup("<p>This <i>is</i> a <i>test</i>.</p>"); myi = s.find("i")
                  >>> myi.replaceWith("was")
                  >>> s.find("i")
                  <i>test</i>
                  

                  请注意第 4 行后 s.find("i") 的缺失输出!

                  Please note the missing output of s.find("i") after line 4!

                  这是什么原因?有解决办法吗?

                  What's the reason for this? Is there a workaround?

                  实际上,该示例并未演示用例,即:

                  Actually, the example doesn't demonstrate the usecase, which is:

                  myi.replaceWith(BeautifulSoup("wa<b>s</b>"))
                  

                  每当插入的部分包含自己重要的 html 代码时,我看不出如何用其他内容替换此语法.只是有

                  Whenever the inserted part contains itself nontrivial html code, I don't see how you could replace this syntax with something else. Just having

                  myi.replaceWith("wa<b>s</b>")
                  

                  将用实体替换 html 特殊字符.

                  will replace the html special chars by entities.

                  推荐答案

                  更简单的答案:调用 replaceWith 后,通过调用 s 重新生成并清理 s= BeautifulSoup(s.renderContents()).然后你就可以再次find了.

                  Simpler answer : after your call to replaceWith, regenerate and clean s by calling s = BeautifulSoup(s.renderContents()). Then you can find again.

                  这篇关于replaceWith() 后的 find() 不起作用(使用 BeautifulSoup)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:优化的切割/切片排序列表的方法 下一篇:使用 Python 在 Excel (.xlsx) 中查找和替换字符串

                  相关文章

                • <tfoot id='DNQIv'></tfoot>
                  <legend id='DNQIv'><style id='DNQIv'><dir id='DNQIv'><q id='DNQIv'></q></dir></style></legend>
                    <i id='DNQIv'><tr id='DNQIv'><dt id='DNQIv'><q id='DNQIv'><span id='DNQIv'><b id='DNQIv'><form id='DNQIv'><ins id='DNQIv'></ins><ul id='DNQIv'></ul><sub id='DNQIv'></sub></form><legend id='DNQIv'></legend><bdo id='DNQIv'><pre id='DNQIv'><center id='DNQIv'></center></pre></bdo></b><th id='DNQIv'></th></span></q></dt></tr></i><div id='DNQIv'><tfoot id='DNQIv'></tfoot><dl id='DNQIv'><fieldset id='DNQIv'></fieldset></dl></div>
                      <bdo id='DNQIv'></bdo><ul id='DNQIv'></ul>

                    1. <small id='DNQIv'></small><noframes id='DNQIv'>