I wanted to find a way to parse information from:
<tr>
<td class="prodSpecAtribute">Rulebook Chapter</td>
<td colspan="5">
<a href="http://cmegroup.com/rulebook/CME/V/450/452/452.pdf" target="_blank" title="CME Chapter 452">CME Chapter 452</a>
</td>
</tr>
<tr>
<td class="prodSpecAtribute" rowspan="2">
Trading Hours
<br>
(All times listed are Central Time)
</td>
<td>OPEN OUTCRY</td>
<td colspan="4">
<div class="font_black Large_div_td">MON-FRI: 7:20 a.m. - 2:00 p.m.</div>
</td>
</tr>
<tr>
<td>CME GLOBEX</td> #PROBLEM HERER -- WANT this and div below to be one row, considered under class <td class="prodSpecAtribute" rowspan="2"> ... Trading Hours...
<td colspan="4">
<div class="font_black Large_div_td">SUN - FRI: 5:00 p.m. - 4:00 p.m. CT</div>
</td>
</tr>
I was able to parse information in the top table easily as follows:
soup = BeautifulSoup(page)
left_col = soup.findAll('td', attrs={'class' : 'prodSpecAtribute'})
right_col= soup.findAll('td', colspan=['4', '5'])
So in this example there are 3 rows:
2 have class "prodSpecAtribute" and atleast one column corresponding to each class.
However, the last row, has no class, so I need a way to use the last class and define this new under the same class, along with the 2 of the third row's <td>s: CME GLOBEX and SUN - FRI: 5:00 p.m. - 4:00 p.m. CT
Combine_column method:
def combine_col(right):
num = len(right)
for i in range(0, num):
text_ = ' '.join(right[i].findAll(text=True))
print text_
return text_