Wie kann ich alle td
Informationen aus diesen HTML-Daten abrufen:Extrahieren von Inhalt von zwei Tabellen aus Web-Daten
<h1>All staff</h1>
<h2>Manager</h2>
<table class="StaffList">
<tbody>
<tr>
<th>Name</th>
<th>Post title</th>
<th>Telephone</th>
<th>Email</th>
</tr>
<tr>
<td>
<a href="http://profiles.strx.usc.com/Profile.aspx?Id=Jon.Staut">Jon Staut</a>
</td>
<td>Line Manager</td>
<td>0160 315 3832</td>
<td>
<a href="mailto:[email protected]">[email protected]</a> </td>
</tr>
</tbody>
</table>
<h2>Junior Staff</h2>
<table class="StaffList">
<tbody>
<tr>
<th>Name</th>
<th>Post title</th>
<th>Telephone</th>
<th>Email</th>
</tr>
<tr>
<td>
<a href="http://profiles.strx.usc.com/Profile.aspx?Id=Peter.Boone">Peter Boone</a>
</td>
<td>Mailer</td>
<td>0160 315 3834</td>
<td>
<a href="mailto:[email protected]">[email protected] </a>
</td>
</tr>
<tr>
<td>
<a href="http://profiles.strx.usc.com/Profile.aspx?Id=John.Peters">John Peters</a>
</td>
<td>Builder</td>
<td>0160 315 3837</td>
<td>
<a href="mailto:[email protected]">[email protected]</a>
</td>
</tr>
</tbody>
</table>
Hier ist mein Code, der einen Fehler erzeugt:
response =requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.findAll('table', attrs={'class': 'StaffList'})
list_of_rows = []
for row in table.findAll('tr'): #2 rows found in table -loop through
list_of_cells = []
for cell in row.findAll('td'): # each cell in in a row
text = cell.text.replace(' ','')
list_of_cells.append(text)
#print list_of_cells
list_of_rows.append(list_of_cells)
#print all cells in the two rows
print list_of_rows
Fehlermeldung:
AttributeError: 'ResultSet' object has no attribute 'findAll'
Was muss ich tun, um den Code alle Informationen in den beiden Web-ta ausgeben zu lassen Bles?
Warum versuchst du nicht direkt 'sup.findAll ('td')'? – estebanpdl