I've a table on a website much like this:
<table class="table-class">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Hello</td>
<td>A number</td>
<td>Another number<td>
</tr>
<tr>
<td>there</td>
<td>A number</td>
<td>Another number<td>
</tr>
</tbody>
</table>
Ultimately, what I would like to do is to read the content of each td
for each row and produce a string containing all three cells for each respective row. Furthermore, I would like for this to scale to handle larger tables from numerous websites using the same design, so speed is somewhat of a priority, but not a necessity.
I assume I have to use something like find_elements_by_xpath(...)
or similar, but I'm really hitting a wall with this. I've attempted several approaches suggested on other sites and seem to do more things wrong than right. Any sort of suggestion or idea would be hugely appreciated!
What I currently have, although non-functioning and based on another question from here, is:
listoflist = [[td.text
for td in tr.find_elements_by_xpath('td')]
for tr in driver.find_elements_by_xpath("//table[@class='table-class')]//tr"]
listofdict = [dict(zip(list_of_lists[0],row)) for row in list_of_lists[1:]]
Thanks in advance!
vham