MCPcopy Create free account
hub / github.com/clips/pattern / search

Method search

pattern/web/soup/BeautifulSoup.py:950–975  ·  view source on GitHub ↗
(self, markup)

Source from the content-addressed store, hash-verified

948 return found
949
950 def search(self, markup):
951 #print 'looking for %s in %s' % (self, markup)
952 found = None
953 # If given a list of items, scan it for a text element that
954 # matches.
955 if hasattr(markup, "__iter__") \
956 and not isinstance(markup, Tag):
957 for element in markup:
958 if isinstance(element, NavigableString) \
959 and self.search(element):
960 found = element
961 break
962 # If it's a Tag, make sure its name or attributes match.
963 # Don't bother with Tags if we're searching for text.
964 elif isinstance(markup, Tag):
965 if not self.text:
966 found = self.searchTag(markup)
967 # If it's text, make sure the text matches.
968 elif isinstance(markup, NavigableString) or \
969 isinstance(markup, basestring):
970 if self._matches(markup, self.text):
971 found = markup
972 else:
973 raise Exception, "I don't know how to match against a %s" \
974 % markup.__class__
975 return found
976
977 def _matches(self, markup, matchAgainst):
978 #print "Matching %s against %s" % (markup, matchAgainst)

Callers 5

_findAllMethod · 0.95
_matchesMethod · 0.45
endDataMethod · 0.45
start_metaMethod · 0.45
_detectEncodingMethod · 0.45

Calls 2

searchTagMethod · 0.95
_matchesMethod · 0.95

Tested by

no test coverage detected