parse_table¶
-
pyrcs.utils.
parse_table
(source, parser='lxml')[source]¶ Parse HTML <tr> elements for creating a data frame.
- Parameters
source (requests.Response) – response object to connecting a URL to request a table
parser (str) –
'lxml'
(default),'html5lib'
or'html.parser'
- Returns
a list of lists each comprising a row of the requested table (see also parse_tr()) and a list of column names of the requested table
- Return type
tuple
Examples:
>>> from pyrcs.utils import fake_requests_headers, parse_table >>> source_ = requests.get('http://www.railwaycodes.org.uk/elrs/elra.shtm', ... headers=fake_requests_headers()) >>> parsed_contents = parse_table(source_, parser='lxml') >>> type(parsed_contents) <class 'tuple'> >>> type(parsed_contents[0]) <class 'list'> >>> type(parsed_contents[1]) <class 'list'>