Quick reference

You can take a look at the following references to get an overview of the modifying content:

  • Modifying the Tag name:

    The following code line modifies the name property:

    • tag.name = "newvalue": This line of code modifies the Tag name as newvalue
  • Modifying the Tag attribute:

    The following code lines alter the attributes:

    • tag["attr"] = "newvalue": This line of code modifies the Tag attribute
    • del tag["attr"]: This line of code deletes the Tag attribute
  • Adding new tags:

    The following code lines correspond to the addition of content:

    • newtag = soup.new_tag('tagname'): This line of code creates newtag
    • oldtag.append(newtag): This line of code appends newtag to oldtag.contents
    • oldtag.insert(0,newtag): This line of code inserts newtag at the index 0

Get Getting Started with Beautiful Soup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.