Python 美化组在父DIV的子DIV内添加新标记

Python 美化组在父DIV的子DIV内添加新标记,python,html,parsing,beautifulsoup,Python,Html,Parsing,Beautifulsoup,我是BeautifulSoup的完全初学者,现在我正在尝试将一个新标记插入父div的children div中 基本上我有一个HTML片段: <div class=page-content> <div class="content-block"> //Insert here! </div> </div> 我可以获取页面内容及其子内容块DIV,但append函数不起任何作用,这是我得到的输出: [<div class="c

我是BeautifulSoup的完全初学者,现在我正在尝试将一个新标记插入父div的children div中

基本上我有一个HTML片段:

 <div class=page-content>
  <div class="content-block">
   //Insert here!
  </div>
 </div>
我可以获取页面内容及其子内容块DIV,但append函数不起任何作用,这是我得到的输出:

 [<div class="content-block">\n</div>, <a class="button active">This is a new button!</a>]
[\n,这是一个新按钮!]

发现问题,我必须使用findNext而不是findChildren。现在append工作正常。

发现了问题,我不得不使用findNext而不是findChildren。现在,append可以正常工作了。

您确定错误不是因为您遗漏了类周围的引号吗?您已经编写了
而不是

你确定错误不是因为你在课堂上遗漏了引号吗?您已经编写了


而不是

也就是说,这不是OP的python问题的原因。我指的是BeautifulSoup,他们的编码器过去常常与引号而不是HTML本身斗争。也就是说,这不是OP的python问题的原因。我指的是BeautifulSoup,他们的编码器过去常常与引号而不是HTML本身斗争。
 [<div class="content-block">\n</div>, <a class="button active">This is a new button!</a>]