MCPcopy Create free account
hub / github.com/csev/py4e / _findAll

Method _findAll

code/BeautifulSoup.py:333–367  ·  view source on GitHub ↗

Iterates over a generator looking for things that match.

(self, name, attrs, text, limit, generator, **kwargs)

Source from the content-addressed store, hash-verified

331 return r
332
333 def _findAll(self, name, attrs, text, limit, generator, **kwargs):
334 "Iterates over a generator looking for things that match."
335
336 if isinstance(name, SoupStrainer):
337 strainer = name
338 # (Possibly) special case some findAll*(...) searches
339 elif text is None and not limit and not attrs and not kwargs:
340 # findAll*(True)
341 if name is True:
342 return [element for element in generator()
343 if isinstance(element, Tag)]
344 # findAll*('tag-name')
345 elif isinstance(name, basestring):
346 return [element for element in generator()
347 if isinstance(element, Tag) and
348 element.name == name]
349 else:
350 strainer = SoupStrainer(name, attrs, text, **kwargs)
351 # Build a SoupStrainer
352 else:
353 strainer = SoupStrainer(name, attrs, text, **kwargs)
354 results = ResultSet(strainer)
355 g = generator()
356 while True:
357 try:
358 i = g.next()
359 except StopIteration:
360 break
361 if i:
362 found = strainer.search(i)
363 if found:
364 results.append(found)
365 if limit and len(results) >= limit:
366 break
367 return results
368
369 #These Generators can be used to navigate starting from both
370 #NavigableStrings and Tags.

Callers 6

findAllNextMethod · 0.95
findNextSiblingsMethod · 0.95
findAllPreviousMethod · 0.95
findPreviousSiblingsMethod · 0.95
findParentsMethod · 0.95
findAllMethod · 0.45

Calls 5

searchMethod · 0.95
SoupStrainerClass · 0.70
ResultSetClass · 0.70
nextMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected