BeautifulSoup get_text from find_all

This is my first web scraping job. So far, I can navigate and find the part of HTML that I want. I can print it. The problem is to print only text that will not work. When trying to get the following error:AttributeError: 'ResultSet' object has no attribute 'get_text'

Here is my code:

from bs4 import BeautifulSoup
import urllib

page = urllib.urlopen('some url')


soup = BeautifulSoup(page)
zeug = soup.find_all('div', attrs={'class': 'fm_linkeSpalte'}).get_text()


print zeug
+4
source share
2 answers

find_all()returns an array of elements. You have to go through all of them and choose the one that you need. And what to callget_text()

UPD
For example:

    for el in soup.find_all('div', attrs={'class': 'fm_linkeSpalte'}):
        print el.get_text()

But note that you may have several items.

+11
source

, , , , , , , , ... ...

:

for el in soup.findAll('div', attrs={'class': 'fm_linkeSpalte'}):
    print ''.join(el.findAll(text=True))

, .

0

All Articles