My data sample :
<table id = "history">
<tr class = "printCol">
<td class="name">Google</td><td class="date">07/11/2001</td><td class="state">
<span>CA</span>
</td>
</tr>
<tr class = "printCol">
<td class="name">Apple</td><td class="date">27/08/2001</td>
</tr>
<tr class = "printCol">
<td class="name">Microsoft</td><td class="date">01/11/1991</td>
</tr>
</table>
Beautifulsoup code :
table = soup.find("table", id = "history")
rows = table.findAll('tr')
for tr in rows:
cols = tr.findAll('td')
for td in cols:
print td.find(text=True)
Desired Output for MySQL storage (list):
['Google|07/11/2001|CA', 'Apple|27/08/2001', 'Microsoft|01/11/1991']
Output I have (difficult to associate the right date to the right company) :
Google
07/11/2001
Apple
27/08/2001
Microsoft
01/11/1991
I wrote a function to extract elements from each tr but I thought there is a much more efficient way of doing it all in the original for loop. I want to store them in a list as data pairs. Thoughts?