diff options
author | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 14:32:49 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2017-05-06 14:32:49 -0400 |
commit | db3b9cf9e69aec1e333c17e52fe6d7cf56c0bf2f (patch) | |
tree | 7f9c99297e8c7039578423795256fe5f23d248de /doc | |
parent | c8221ac4a36666b775f2f77920b3a5071109d374 (diff) | |
download | beautifulsoup4-db3b9cf9e69aec1e333c17e52fe6d7cf56c0bf2f.tar.gz |
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]
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/index.rst | 14 |
1 files changed, 10 insertions, 4 deletions
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('<p class="body strikeout"></p>') - css_soup.p['class'] - # ["body", "strikeout"] - css_soup = BeautifulSoup('<p class="body"></p>') css_soup.p['class'] # ["body"] + + css_soup = BeautifulSoup('<p class="body strikeout"></p>') + 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) # <p>Back to the <a rel="index contents">homepage</a></p> +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('<p class="body strikeout"></p>', 'xml') |