CDNthe2nd
CDNthe2nd

Reputation: 369

'NoneType' object has no attribute 'attrs' - If no value = Skip that function

So I have been trying to find out how to solve a issue that I have been stuck on - Basically what I want to do is that whenever there is a "NoneType" on a value = Skip that function so meaning if there is no value then just skip the rest of the code.

So what I have tried to get is

bs4.find("div", {'class': "clock"}).attrs['data-code']

meaning that sometimes this function is not working all the time so I tried to basically do - If there is no value from it then just continue the rest of the code - Else excute it - what I have done is

 if bs4.find("div", {'class': "clock"}).attrs['data-code'] == None:
                 log("Does it work?")
                 gettimer = bs4.find("div", {'class': "clock"}).attrs['data-code']
                 dothemath = int(gettimer) - 189386
                 releasetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(dothemath))

The issue im getting now that it stops whenever it reach to the if statement because it can't find the value and it automatic stops there - What can I do so whenever there is NoneType on it, Just skip the rest of the code?

Upvotes: 0

Views: 1586

Answers (1)

Barmar
Barmar

Reputation: 780798

Use try/except:

try:
    gettimer = bs4.find("div", {'class': "clock"}).attrs['data-code']
    // rest of code
except:
    pass

Upvotes: 1

Related Questions