Repeating

class stere.areas.Repeating
Parameters:
  • root (Field) – A non-unique root to search for.
  • repeater (Repeating | Area) – The object that repeats on the page.

Represents abstract non-unique collections that repeat, based on a common root.

This can be used to identify anything that not only appears multiple times, but also contains things which appear multiple times.

Repeating are inherently confusing and should only be used if something appears multiple times, contains something else that appears multiple times, and is truly non-unique with no other way to target it.

The last object in a chain of Repeating must be a RepeatingArea. This is because ultimately, there must be an end to the number of things that repeat.

Example

A page where multiple “project” containers appear, each with a table of items.

>>> from stere.areas import Repeating, RepeatingArea
>>> from stere.fields import Root, Link, Text
>>>
>>> projects = Repeating(
>>>     root=Root('css', '.projectContainer'),
>>>     repeater=RepeatingArea(
>>>         root=Root('xpath', '//table/tr'),
>>>         description=Link('xpath', './td[1]'),
>>>         cost=Text('xpath', './td[2]'),
>>>    )
>>> )
>>>
>>> assert 2 == len(projects.children)
>>> first_project = projects.children[0]
>>> assert first_project.areas.contains(
>>>     'description', 'Solar Panels')
>>>
>>> second_project = projects.children[1]
>>> assert second_project.areas.contains(
>>>     'description', 'Self-Driving Cars')
new_container()

Must return an object to contain results from Repeater.children()

By default a list is returned.

Returns:list
children()

Find all instances of the root, then return a collection containing children built from those roots.

The type of collection is determined by the Repeating.new_container() method.

Returns:list-like collection of every repeater that was found.
has_children()

Check if any children can be found.

Parameters:
  • minimum – Minimum number of children that must exist.
  • retry_time – Number of seconds to check for.
Returns:

bool