-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
32 lines (18 loc) · 773 Bytes
/
example.py
File metadata and controls
32 lines (18 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from bs4 import BeautifulSoup as bs
from html_table_parser import parser_functions as parse
from html_table_parser.tests import test_html_table_parser as test
import pprint
pp = pprint.PrettyPrinter(indent=4, width=120)
__author__ = 'oswaldjones'
if __name__ == '__main__':
soup = bs(test.mock_html_table(), "html.parser")
test_table = soup.find('table')
twod_array = parse.make2d(test_table)
# print 2D array
pp.pprint(twod_array)
# print column data by col heading name (case insensitive)
pp.pprint(parse.twod_col_data(twod_array, 'first name'))
pp.pprint(parse.twod_col_data(twod_array, 'lAst naMe'))
# row data begins on first row after col headings
# so rowstart is 1
pp.pprint(parse.make_dict(test_table, 1))