From 13ec3c3f3010820be225094cc06862cc4b3b2944 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 6 May 2017 14:32:49 -0400 Subject: Added the method, which acts like for getting the value of an attribute, but which joins attribute multi-values into a single string value. [bug=1678589] --- doc/source/index.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'doc/source/index.rst') diff --git a/doc/source/index.rst b/doc/source/index.rst index 56aa7fe..0d13e0a 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -402,13 +402,13 @@ 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"] + + css_soup = BeautifulSoup('

') + css_soup.p['class'] + # ["body", "strikeout"] If an attribute `looks` like it has more than one value, but it's not a multi-valued attribute as defined by any version of the HTML @@ -428,6 +428,12 @@ consolidated:: print(rel_soup.p) #

Back to the homepage

+You can use ```string_attr`` to get the value of any attribute as a +string, whether or not it's a multi-valued atribute:: + + css_soup.p.string_attr('class') + # "body strikeout" + If you parse a document as XML, there are no multi-valued attributes:: xml_soup = BeautifulSoup('

', 'xml') -- cgit v1.2.3