help with indentation that is generating error in python 3.6

1

I'm doing a webcrawler I'm having the following problem. I had to do a separate program to print out how many candidates passed each course. Except that the last line is not being executed, and that it would make the vector names go to the next course of the list. The line that is not running is the last one that is written: position = position +1 +1  The code is this

from bs4 import BeautifulSoup
import requests  
import string
import re
import urllib 
cursos = [
'ADMINISTRAÇÃO - GOVERNADOR VALADARES - DIURNO - SISU - GRUPO A',
'ADMINISTRAÇÃO - GOVERNADOR VALADARES - DIURNO - SISU - GRUPO B',  
'ADMINISTRAÇÃO - GOVERNADOR VALADARES - DIURNO - SISU - GRUPO D',
'ADMINISTRAÇÃO - GOVERNADOR VALADARES - DIURNO - SISU - GRUPO E',
'ADMINISTRAÇÃO - JUIZ DE FORA - DIURNO - SISU - GRUPO A',
'ADMINISTRAÇÃO - JUIZ DE FORA - DIURNO - SISU - GRUPO B'

]

r = requests.get('http://www.ufjf.br/cdara/sisu-2/sisu-2017-1a-edicao/lista-de-espera-sisu-3/?id_curso=05GV&id_grupo=72')
soup = BeautifulSoup(r.text, "html.parser")
vetor = [] 
posicao =1
for node in soup.findAll("td"):
  candidato =node.get_text("td")
  vetor.append(candidato)
  contador = 0

  for s in vetor:
   contador = contador +1
  contador = int(contador/5)
  contador = 5
  contador2 = 0
  contador2 = int(contador2)
  print(contador)
  while contador2<=contador:
   print(cursos[posicao])
  posicao = posicao +1   
    
asked by anonymous 02.03.2017 / 23:24

2 answers

1

The position is not being incremented in the while loop

while contador2 <= contador:
    print(cursos[posicao])
    posicao = posicao +1
    
18.07.2018 / 22:20
0

Firstly I suggest you follow the pep8 style guide ( link ) that recommends 4 indentation spaces .

Specifically about your problem: Change your While block (last block before the line that you mention) to the following:

while contador2<=contador:
    print ('contador: ', contador, 'contador2: ' contador2)

And you will see that you are actually entering an infinite loop, since the variable "counter" will always have a value of 5 and the variable "counter2" will have a value of 0 (zero).

Correct this while and the line that increments the position will be reached.

Again: Follow convention style, indentation with 4 spaces; ALWAYS.

    
03.03.2017 / 00:49