diff options
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/element.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/bs4/element.py b/bs4/element.py index d2fa19f..4ff9cd4 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1156,7 +1156,7 @@ class SoupStrainer(object): found = markup else: found = markup_name - if found and self.text and self.text != found.string: + if found and self.text and not self._matches(found.string, self.text): found = None return found searchTag = search_tag @@ -1188,7 +1188,7 @@ class SoupStrainer(object): return found def _matches(self, markup, match_against): - # print "Matching %s against %s" % (markup, match_against) + #print "Matching %s against %s" % (markup, match_against) result = False if isinstance(markup, list) or isinstance(markup, tuple): diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index e9a5763..4d114b7 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -126,6 +126,18 @@ class TestFindAllByName(TreeTest): self.assertSelects( self.tree.find_all('a'), ['First tag.', 'Nested tag.']) + def test_find_all_by_name_and_text(self): + self.assertSelects( + self.tree.find_all('a', text='First tag.'), ['First tag.']) + + self.assertSelects( + self.tree.find_all('a', text=True), ['First tag.', 'Nested tag.']) + + self.assertSelects( + self.tree.find_all('a', text=re.compile("tag")), + ['First tag.', 'Nested tag.']) + + def test_find_all_on_non_root_element(self): # You can call find_all on any node, not just the root. self.assertSelects(self.tree.c.find_all('a'), ['Nested tag.']) |