How can I insert a new tag into a BeautifulSoup object?

前端 未结 3 2091
小鲜肉
小鲜肉 2020-11-30 08:39

Trying to get my head around html construction with BS.

I\'m trying to insert a new tag:

self.new_soup.body.insert(3, \"\"\"
3条回答
  •  孤街浪徒
    2020-11-30 09:04

    Use the factory method to create new elements:

    new_tag = self.new_soup.new_tag('div', id='file_history')
    

    and insert it:

    self.new_soup.body.insert(3, new_tag)
    

提交回复
热议问题