9. Example #6
class_soup=BeautifulSoup('<pclass="bodystrikeout"></p>'
printclass_soup.p['class'] #["body","strikeout"]
class_soup=BeautifulSoup('<pclass="body"></p>')
printclass_soup.p['class'] #["body"]
id_soup=BeautifulSoup('<pid="myid"></p>')
printid_soup.p['id'] #'myid'
#----------
rel_soup=BeautifulSoup('<p>Backtothe<arel="index">homepage</a></p>'
printrel_soup.a['rel'] #['index']
rel_soup.a['rel']=['index','contents']
print(rel_soup.p) #<p>Backtothe<arel="indexcontents">homepage</a></p>
#----------
xml_soup=BeautifulSoup('<pclass="bodystrikeout"></p>',
printxml_soup.p['class'] #u'bodystrikeout'
['body','strikeout']
['body']
myid
#----------
['index']
<p>Backtothe<arel="indexcontents">homepage</a></p>
#----------
bodystrikeout
When you turn a tag back into a string, multiple attribute
values are consolidated.
If you parse a document as XML, there are no multi-
valued attributes.
The relattribute specifies the relationship between the
current document and the linked document (Only used if
the hrefattribute is present).
9 / 20