Why am I getting “'ResultSet' has no attribute 'findAll'” using BeautifulSoup in Python?

霸气de小男生 提交于 2019-12-04 03:43:49
bernie

Wow. Triptych provided a great answer to a related question.

We can see, from BeautifulSoup's source code, that ResultSet subclasses list.

In your example, get_rows is an instance of BS's ResultSet class,
and since BS's ResultSet subclasses list, that means get_rows is a list.

get_rows, as an instance of ResultSet, does not have a findAll method implemented; hence your error.
What Triptych has done differently is to iterate over that list.
Triptych's method works because the items in the get_rows list are instances of BS's Tag class; which has a findAll method.

So, to fix your code, you could replace the last three lines of your create method with something like this:

for row in get_rows:
    text = ''.join(row.findAll(text=True))
    data = text.strip()
    print data

Note to Leonard Richardson: in no way do I intend to demean the quality of your work by referring to it as BS ;-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!