Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I'm scraping a table from a Wikipedia page and it is showing error: attribute error. Here is my code:
right_table=soup.find_all('table',class_="nowraplinks collapsible autocollapse navbox-inner")
print(right_table)
print(type(right_table)) <class 'bs4.element.resultset'>
I want to iterate into each row, but it is showing error
for row in right_table.find_all('tr'):
print(row)
The error is:
AttributeError: ResultSet object has no attribute 'find_all'. You're
probably treating a list of items like a single item. Did you call
find_all() when you meant to call find()?
Welcome to both stackoverflow and BeautifulSoup.
The result of a find_all will be a list. For which you can not apply find_all() again as it will be going for a list.
You have to do something like (if you have only one table),
right_table=soup.find('table',class_="nowraplinks collapsible autocollapse navbox-inner")
for row in right_table.find_all('tr'):
print(row)
or if you have multiple tables you need to add another for loop, like,
right_table=soup.find('table',class_="nowraplinks collapsible autocollapse navbox-inner")
for table in right_table:
for row in table.find_all('tr'):
print(row)
Hope this helps! Cheers!