I'm trying to make python script that gets all the grades of the student using requests and bs4. Now i have a problem looping the values
for rows in tr:
td = tbody.find_all('td')
subject.append(td[0].get_text())
fq.append(td[1].get_text())
sq.append(td[2].get_text())
ave.append(td[3].get_text())
for i in subject:
print(f"Subject: {i}")
for i in fq:
print(f"First Quarter: {i}")
for i in sq:
print(f"Second Quarter: {i}")
for i in ave:
print(f"Average: {i}")
# here my goal is there are 4 list and are all connected like all the first value of the subject list, f_quar, s_quar and the average are linked together, like gen math(subject), 90(f_qaur), 90(s_qaur), and 90(average)
Output:
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
Subject: GENERAL MATHEMATICS
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
First Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Second Quarter: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Average: ##.00
Expected Output:
Subject: Gen Math
Subject: Stats
...
First Quarter: 90.00
First Quarter: 90.00
...
Second Quarter: 90.00
Second Quarter: 90.00
...
Average: 90.00
Average: 90.00
...
Im new at pyton so loops is my weakness. Also the code seems so wrong since i need the subject, 1stQ grade, 2ndQ grade and the average. Thanks!. This is the html code of the table:
<table cellspacing="0" class="table table-bordered table-striped" id="tblss1" width="100%">
<thead>
<tr class="success">
<th style="text-align:center">SUBJECT</th>
<th style="text-align:center">1ST</th>
<th style="text-align:center">2ND</th>
<th style="text-align:center">AVE</th>
</tr>
</thead>
<tbody>
<tr>
<td style="color:purple"> GENERAL MATHEMATICS </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> EARTH SCIENCE </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> PHYSICAL EDUCATION AND HEALTH </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.50 </strong></td>
</tr>
<tr>
<td style="color:purple"> GENERAL CHEMISTRY 1 </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> 21ST CENTURY LITERATURE </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> READING AND WRITING </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> GENERAL BIOLOGY 1 </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.00 </strong></td>
</tr>
<tr>
<td style="color:purple"> ENTREPRENEURSHIP </td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center"> <strong> ##.00 </strong></td>
<td align="center" style="color:blueviolet"> <strong> ##.50 </strong></td>
</tr>
</tbody>
</table>