parse_table¶
-
pyrcs.utils.
parse_table
(source, parser='lxml')¶ 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 >>> example_url = 'http://www.railwaycodes.org.uk/elrs/elra.shtm' >>> source_dat = requests.get(example_url, headers=fake_requests_headers()) >>> parsed_contents = parse_table(source_dat, parser='lxml') >>> type(parsed_contents) tuple >>> type(parsed_contents[0]) list >>> type(parsed_contents[1]) list