Python Forum

Full Version: NoneType allways a problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I got a problem
I use the following code to get the elements from one webpage. The problem is I can't save the value if the item is none
The problem exists when I write

 ws['G'+str(i)] =  keywords['content']
Got the error:
Error:
Traceback (most recent call last): File "C:\Users\ASUS PC\AppData\Local\Programs\Python\Python36\getdescription.py", line 122, in <module> h= keywords['content'] TypeError: 'NoneType' object is not subscriptable
If the values are empty I want to write "Blank Value"

from openpyxl import load_workbook
wb2 = load_workbook('teste.xlsx')
ws=wb2.active
last_row = ws.max_row
print(last_row)
for i in range(1,last_row+1):
    al=ws['B'+str(i)]
    print(al.value)
    b=al.value
    if(b is not None and 'T' in b): #vai buscar o titulo
        print('Processando o link '+ws['A'+str(i)].value)
        titulo=buscaTitulo(ws['A'+str(i)].value)        
        ws['C'+str(i)] = titulo
    if(b is not None and 'D' in b): #vai buscar a descricao
        print('Processando o link '+ws['A'+str(i)].value)
        descricao=buscaDescricao(ws['A'+str(i)].value)                        
        ws['E'+str(i)] = descricao['content']
    if(b is not None and 'K' in b): #vai buscar a keyword
        print('Processando o link '+ws['A'+str(i)].value)
        keywords=buscaKeyword(ws['A'+str(i)].value)
        ws['G'+str(i)] =  keywords['content']                 
#ws['F5'] = "teste"
wb2.save('teste.xlsx')
Solved


...
 if keywords:
   u=keywords['content']
 else:
   u="Nada"