From 0cdcc79fb1332d6f7ac2b085ec654adfef50ac86 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 29 Jan 2023 10:37:49 -0500 Subject: Reworded the 'multi-valued attributes' portion of the documentation to make it more clear. [bug=1970767] --- doc/source/index.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'doc/source/index.rst') diff --git a/doc/source/index.rst b/doc/source/index.rst index 7288024..007e75f 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -366,8 +366,8 @@ 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:: +``headers``, and ``accesskey``. By default, Beautiful Soup parses the value(s) +of a multi-valued attribute into a list:: css_soup = BeautifulSoup('

', 'html.parser') css_soup.p['class'] @@ -388,15 +388,16 @@ standard, Beautiful Soup will leave the attribute alone:: When you turn a tag back into a string, multiple attribute values are consolidated:: - rel_soup = BeautifulSoup('

Back to the homepage

', 'html.parser') + rel_soup = BeautifulSoup('

Back to the homepage

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

Back to the homepage

-You can disable this by passing ``multi_valued_attributes=None`` as a -keyword argument into the ``BeautifulSoup`` constructor:: +You can force all attributes to be parsed as strings by passing +``multi_valued_attributes=None`` as a keyword argument into the +``BeautifulSoup`` constructor:: no_list_soup = BeautifulSoup('

', 'html.parser', multi_valued_attributes=None) no_list_soup.p['class'] -- cgit v1.2.3