From ffcebc274b84b85a0b8c93c2aca8756df4baa236 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 16 Feb 2012 13:31:20 -0500 Subject: Issue a warning if characters were replaced with REPLACEMENT CHARACTER during Unicode conversion. --- bs4/doc/source/index.rst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'bs4/doc/source') diff --git a/bs4/doc/source/index.rst b/bs4/doc/source/index.rst index 8328ed7..200317a 100644 --- a/bs4/doc/source/index.rst +++ b/bs4/doc/source/index.rst @@ -303,19 +303,24 @@ done by treating the tag as a dictionary:: Multi-valued attributes &&&&&&&&&&&&&&&&&&&&&&& -HTML defines a few attributes that can have multiple values. The most -common is ``class`` (a tag can have more than one CSS class), but -there are a few others: ``rel``, ``rev``, ``archive``, -``accept-charset``, and ``headers``. If one of these attributes has -more than one value, Beautiful Soup will turn its values into a list:: +HTML 4 defines a few attributes that can have multiple values. HTML 5 +removes a couple of them, but defines a few more. The most common +multi-valued attribute is ``class`` (that is, a tag can have more than +one CSS class). Others include ``rel``, ``rev``, ``accept-charset``, +``headers``, and ``accesskey``. Beautiful Soup presents the value(s) +of a multi-valued attribute as a list:: css_soup = BeautifulSoup('

') css_soup.p['class'] # ["body", "strikeout"] + css_soup = BeautifulSoup('

') + css_soup.p['class'] + # ["body"] + If an attribute `looks` like it has more than one value, but it's not -one of the special attributes listed above, Beautiful Soup will leave -the attribute alone:: +a multi-valued attribute as defined by any version of the HTML +standard, Beautiful Soup will leave the attribute alone:: id_soup = BeautifulSoup('

') id_soup.p['id'] @@ -326,11 +331,19 @@ consolidated:: rel_soup = BeautifulSoup('

Back to the homepage

') rel_soup.a['rel'] - # 'index' + # ['index'] rel_soup.a['rel'] = ['index', 'contents'] print(rel_soup.p) #

Back to the homepage

+If you parse a document as XML, there are no multi-valued attributes:: + + xml_soup = BeautifulSoup('

', 'xml') + xml_soup.p['class'] + # u'body strikeout' + + + ``NavigableString`` ------------------- -- cgit v1.2.3