Using only selenium and python, here's something you can achieve:
# Retrieve the headers of each cell
table_headers = [el.text for el in driver.find_elements_by_css_selector("table td.tableheading")]
table_row = []
table = []
for tr in driver.find_elements_by_css_selector("table table tr"):
cells = [el.text for el in tr.find_elements_by_css_selector('td.tableCell')]
if len(cells) > 0:
table_row.append(cells)
# Create your table [row, dict of header/value]
for row in table_row:
table.append(dict(zip(table_headers, row)))
Output:
[{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': ''},
{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': ''},
{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': 'col4 data'}]
[{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': ''},
{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': ''},
{'Column 1': 'col1 data',
'Column 2': 'col2 data',
'Column 3': 'col3 data',
'Column 4': 'col4 data'}]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…