get_heading_text

pyrcs.parser.get_heading_text(heading_tag, elem_tag_name='em')[source]

Get the text of a given heading tag.

Parameters:
  • heading_tag (bs4.element.Tag) – tag of a heading

  • elem_tag_name (str) – tag name of an element in the heading_tag, defaults to 'em'

Returns:

cleansed text of the given heading_tag

Return type:

str

Examples:

>>> from pyrcs.parser import get_heading_text
>>> from pyrcs.line_data import Electrification

>>> elec = Electrification()

>>> url = elec.catalogue[elec.KEY_TO_INDEPENDENT_LINES]
>>> source = requests.get(url=url, headers=fake_requests_headers())
>>> soup = bs4.BeautifulSoup(markup=source.content, features='html.parser')

>>> h3 = soup.find('h3')

>>> h3_text = get_heading_text(heading_tag=h3, elem_tag_name='em')
>>> h3_text
'Beamish Tramway'