diff options
author | Leonard Richardson <leonardr@segfault.org> | 2015-06-27 12:21:45 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2015-06-27 12:21:45 -0400 |
commit | ab7fa80de890e03919741a61b828305d941c6ab0 (patch) | |
tree | c050535b5a2d3e2dadff0798adb84b9695282255 | |
parent | efc7b53c69117e51b24f406cd6742f65b6a7a62b (diff) | |
download | beautifulsoup4-ab7fa80de890e03919741a61b828305d941c6ab0.tar.gz |
Added an example of using a fuction on an attribute value/using a function to invert a normal search.
-rw-r--r-- | doc/source/index.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst index 821dad4..ee68d99 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1127,6 +1127,17 @@ tags, because those tags define both "class" and "id". It doesn't pick up tags like <html> and <title>, because those tags don't define "class". +If you pass in a function to filter on a specific attribute like +``href``, the argument passed into the function will be the attribute +value, not the whole tag. Here's a function that finds all ``a`` tags +whose ``href`` attribute _does not_ match a regular expression:: + + def not_lacie(href): + return href and not re.compile("lacie").search(href) + soup.find_all(href=not_lacie) + # [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>, + # <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>] + Here's a function that returns ``True`` if a tag is surrounded by string objects:: |