I'm trying to extract the sunrise time (7:56AM) from the below HTML table using Python which I scraped using beautiful soup. It's the "text-right" of the second row, but I can't figure it out or find any resources guiding me, do I loop over the table to the second row?
First Light 7:20AM Sunrise 7:56AM
<table class="table table-sm table-striped table-inverse table-tide">
<tr>
<td><strong>First Light</strong></td>
<td class="text-right"> 7:20AM</td>
</tr>
<tr>
<td><strong>Sunrise</strong></td>
<td class="text-right"> 7:56AM </td>
</tr>
</table>
Excuse the dirty block of code
Thanks in advance.
Yes, you could try to iterate over the td tag like that:
for td in soup.find_all('td', attrs={"class":"text-right"}):
print(td.text)
output:
7:20AM
7:56AM
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.