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
ofoldtag.contents
Modifying the
string
contents:The following code lines are used to modify the
string
content:tag.string = "helloworld"
: This line of code modifiestag.string
tag.append("helloworld")
: This line of code appends"helloworld...