How to change tag name with BeautifulSoup?

后端 未结 3 423
独厮守ぢ
独厮守ぢ 2020-12-03 16:53

I am using python + BeautifulSoup to parse an HTML document.

Now I need to replace all

elements in an HTML document, wit

3条回答
  •  情书的邮戳
    2020-12-03 17:59

    From BeautifulSoup docs

    from BeautifulSoup import BeautifulSoup, Tag
    soup = BeautifulSoup("

    TEXTHERE

    ") tag = Tag(soup, "h1", [("class", "someclass")]) tag.insert(0, "TEXTHERE") soup.h2.replaceWith(tag) print soup #

    TEXTHERE

提交回复
热议问题