次の情報を解析する方法を見つけたかったのです。
<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>
次のように、トップテーブルの情報を簡単に解析できました。
soup = BeautifulSoup(page)
left_col = soup.findAll('td', attrs={'class' : 'prodSpecAtribute'})
right_col= soup.findAll('td', colspan=['4', '5'])
したがって、この例では 3 つの行があります。2 つの行にはclass "prodSpecAtribute"
、各クラスに対応する少なくとも 1 つの列があります。ただし、最後の行にはclass がないため、最後のクラスを使用して、同じクラスの下でこれを定義する方法が必要です<td>
。CME GLOBEX and SUN - FRI: 5:00 p.m. - 4:00 p.m. CT
Combine_column メソッド:
def combine_col(right):
num = len(right)
for i in range(0, num):
text_ = ' '.join(right[i].findAll(text=True))
print text_
return text_