close

[Solved] Attribute: ‘NoneType’ object has no attribute ‘split’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Attribute: ‘NoneType’ object has no attribute ‘split’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Attribute: ‘NoneType’ object has no attribute ‘split’ Error Occurs?

Today I get the following error Attribute: ‘NoneType’ object has no attribute ‘split’ in python.

How To Solve Attribute: ‘NoneType’ object has no attribute ‘split’ Error ?

  1. How To Solve Attribute: 'NoneType' object has no attribute 'split' Error ?

    To Solve Attribute: 'NoneType' object has no attribute 'split' Error It can happen, that the string has nothing inside, than it is “None” type, so what I can suppose is to check first if your string is not “None”

  2. Attribute: 'NoneType' object has no attribute 'split'

    To Solve Attribute: 'NoneType' object has no attribute 'split' Error It can happen, that the string has nothing inside, than it is “None” type, so what I can suppose is to check first if your string is not “None”

Solution 1

It can happen, that the string has nothing inside, than it is “None” type, so what I can suppose is to check first if your string is not “None”

# Extracting the sites
def CiteParser(content):
    soup = BeautifulSoup(content)
    #print soup
    print "---> site #: ",len(soup('cite'))
    result = []
    for cite in soup.find_all('cite'):
        if cite.string is not None:
            result.append(cite.string.split('/'))
            print cite
    return result

Solution 2

for cite in soup.find_all('cite'):
    if( (cite.string is None) or (len(cite.string) == 0)):
        continue
    result.append(cite.string.split('/')[0])

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read