python - using beautifulsoup to get second and third child in BeautifuSoup -


i have table similar below:

<table>     <thead>         <tr>             <th></th>             <th></th>             <th></th>             <th></th>         <tr>     </thead>     <tbody>         <tr>             <td></td>             <td></td>             <td></td>         </tr>         <tr>             <td></td>             <td></td>             <td></td>         </tr>         <tr>             <td></td>             <td></td>             <td></td>         </tr>         <tr>             <td></td>             <td></td>             <td></td>         </tr>         <tr>             <td></td>             <td></td>             <td></td>         </tr>     </tbody> </table> 

i need second , third of each row. using beautifulsoup in python 3.5

right now, i'm doing:

table = soup.find('table', attrs={'id': 'field'})         tbody = table.find('tbody')         records = tbody.find_all('tr')         record = records.find_all('td')         field in records:             print (record[2].text) 

i receiving error:

traceback (most recent call last):   file "c:/users/arcee/pycharmprojects/scraper/main.py", line 33, in <module>     record = records.find_all('td') attributeerror: 'resultset' object has no attribute 'find_all' 

is there easier way second , third td elements?

thanks

you're getting error because of these lines:

records = tbody.find_all('tr') record = records.find_all('td') 

find_all returns list (resultset) of occurrences of searched tag. resultset doesn't have find_all attribute - each individual member of does. so, doing..

records = tbody.find_all('tr') record in records:     print(record.find_all('td')) 

will make code run.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -