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 theTag
name asnewvalue
- Modifying the
Tag
attribute:The following code lines alter the attributes:
tag["attr"] = "newvalue"
: This line of code modifies theTag
attributedel tag["attr"]
: This line of code deletes theTag
attribute
- Adding new tags:
The following code lines correspond to the addition of content:
newtag = soup.new_tag('tagname')
: This line of code createsnewtag
oldtag.append(newtag)
: This line of code appendsnewtag
tooldtag.contents
oldtag.insert(0,newtag)
: This line of code insertsnewtag
at the index0
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.