Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NoneType allways a problem
#1
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')
Reply
#2
Solved


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


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020