I have some HTML:
<td class="course-section-type"><span class="text-capitalize">lecture (5)</span></td>
<td class="course-section-meeting">
<table class="no-borders" width="100%">
<tbody>
<tr>
<td width="23%">MWF</td>
<td width="55%">11:30 AM - 12:20 PM</td>
<td width="22%"><span><a href="http://myurl.com" target="_blank">MGH</a> <span class="sr-only">building room</span> 389</span></td>
</tr>
</tbody>
</table>
</td>
<td class="course-section-sln">00000</td>
I'd like to extract the values of top-level "class" attributes and map them to a list of lower level text. For the above HTML, that would look something like:
data = {
"course-section-type": ["lecture (5)"],
"course-section-meeting": ["MWF", "11:30 AM - 12:20 PM", "MGH", "building room", "389"],
"course-section-sln": ["00000"]
}
I know that I can extract all the text with soup.findAll('td').text, but I don't know how to traverse the html tree nor how to extract the value of a tag attribute. How would I go about doing this?
Any help is appreciated.