clone element with beautifulsoup

前端 未结 3 521
粉色の甜心
粉色の甜心 2020-12-18 18:48

I have to copy a part of one document to another, but I don\'t want to modify the document I copy from.

If I use .extract() it removes the element from

3条回答
  •  青春惊慌失措
    2020-12-18 19:19

    For Python:

    You can copy the parent element like:

    import copy
    p_copy = copy.copy(soup.p)
    print p_copy
    # 

    I want pizza and more pizza!

    Ref: https://www.crummy.com/software/BeautifulSoup/bs4/doc/ Section: Copying Beautiful Soup objects

    Regards.

提交回复
热议问题