I’m trying to pull information from an online hockey game summary about penalties assessed during the game.
The penalties each have xpath:
[…]/div/div[x]/h4
where x is the number of the penalty
Inbetween, there are labels for the period the penalties occurred in, which have xpath:
[…]/div/h3[y]
where y is the number of the period.
The problem is, the start of a new period doesn’t reset the penalty number, and the summary looks like:
First period ([…]/div/h3[1])
Penalty1 ([…]/div/div[1]/h4)
Penalty2 ([…]/div/div[2]/h4)
Second period ([…]/div/h3[2])
Penalty3 ([…]/div/div[3]/h4)
Penalty4 ([…]/div/div[4]/h4)
Penalty5 ([…]/div/div[5]/h4)
Third period ([…]/div/h3[3])
Penalty6 ([…]/div/div[6]/h4)
And obviously, different games have different penalty numbers.
Is there a way I can find how many penalties were assessed in each period of a given game?
In the example above, I would want to know that there were 2 penalties in the first period, 3 in the second, and 1 in the third.
There are CSS selectors I could use in theory, but I'm not sure how I could use them: Every penalty has CSS selector
div class=“boxscore-event-ctn"
and every period has CSS selector
h3 class=“margT40"
However, those same CSS selectors are also used for other elements in the HTML code.
Thank you!!
EDIT: Here's the relevant section of the HTML for a sample game. This game had no penalties in the first period, 3 in the second, and 2 in the third:
<div id="tabcontent102">
<div class="pad40" style="background-image:none;">
<h2>Penalties summary</h2>
<h3 class="margT40">First Period</h3><span>No penalty</span>
<h3 class="margT40">Second period</h3>
<div class="boxscore-event-ctn"><img style="width:40px;height:40px;float:left;"src="https://cdn.wssmedias.com/websimhockey/logos/LHSVL/Toronto.jpg">.
<h4>15:26 T. BERTUZZI (Rudesse)</h4>
<div class="flowfix"></div>
</div>
<div class="boxscore-event-ctn"><img style="width:40px;height:40px;float:left;"src="https://cdn.wssmedias.com/websimhockey/logos/LHSVL/Toronto.jpg">.
<h4>09:40 M. CARLE (Avoir retenu)</h4>
<div class="flowfix"></div>
</div>
<div class="boxscore-event-ctn"><img style="width:40px;height:40px;float:left;"src="https://cdn.wssmedias.com/websimhockey/logos/LHSVL/SanDiego.jpg">.
<h4>05:58 J. JOHNSON (Faire trébucher)</h4>
<div class="flowfix"></div>
</div>
<h3 class="margT40">Third period</h3>
<div class="boxscore-event-ctn"><img style="width:40px;height:40px;float:left;"src="https://cdn.wssmedias.com/websimhockey/logos/LHSVL/SanDiego.jpg">
<h4>13:33 J. BOLL (Trop de joueurs sur la glace - banc)</h4>
<div class="flowfix"></div>
</div>
<div class="boxscore-event-ctn"><img style="width:40px;height:40px;float:left;"src="https://cdn.wssmedias.com/websimhockey/logos/LHSVL/SanDiego.jpg">
<h4>06:36 B. BURNS (Avoir accroché)</h4>
<div class="flowfix"></div>
</div>
<h3 class="margT40">Overtime</h3><span>No penalty</span></div>
</div>