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 | 27648c0d8ba6bd837332ef2e673664797194d101 (patch) | |
tree | 819720ec2542e90a3263730334977ee5c44d4d0f /doc/source | |
parent | 3f1c4950a6e1d3b1e8052a4e2168ce5caf89136e (diff) |
Added an example of using a fuction on an attribute value/using a function to invert a normal search.
Diffstat (limited to 'doc/source')
-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:: |