TypeError: 'NoneType' object is not callable, BeautifulSoup

beautifulsoup, python

Solution

You don't need to parse the divs once again. Try this:

for div in soup.find_all('div', 'res'):
    a = div.find('a', 'yschttl spt')
    if a:
        print a.text
        print
        results.append(a)

Problem

I'm running into a strange error. I'm trying to do some basic parsing. Essentially, I'm gathering data in 'x' format, and want to return everything in a format that I can use. My immediate issue is that my code is returning a strange error. I have looked through some of the other posts / answers on here for the same issue, but out of context... it is truly hard to pinpoint the issue. ``` data = url.text soup = BeautifulSoup(data, "html5lib") results = [] # this is what my result set will end up as def parseDiv(text): #function takes one input parameter - a single div for which it will parse for specific items, and return it all as a dictionary soup2 = BeautifulSoup(text) title = soup2.find("a", "yschttl spt") print title.text print return title.text for result in soup.find_all("div", "res"): """ This is where the data is first handled - this would return a div with links, text, etc - So, I pass the blurb of text into the parseDiv() function """ item = parseDiv(result) results.append(item) ``` Obviously at this point, I've included my needed libraries... When I pull the code for soup2 (the second instantiation of bs4 on my new blurbs of text to be processed), and just print the input of my function, it all works. Here is the error: ``` Traceback (most recent call last): File "testdata.py", line 29, in <module> item = parseDiv(result) File "testdata.py", line 17, in parseDiv soup2 = BeautifulSoup(text) File "C:\Python27\lib\site-packages\bs4\__i markup = markup.read() TypeError: 'NoneType' object is not callable ```

Original source