I'm trying to build a table from information collected on a website.
The problem is that although print comes out as expected, at the time of saving in csv file only the last record is going.
Below the code snippet that is giving me a headache.
titulo = 0
atributo = 1
alinhado = ""
with open(arquivoOutput, 'w') as csvfile:
escrevelinha = csv.writer(csvfile, delimiter=';', quoting=csv.QUOTE_MINIMAL)
escrevelinha.writerow(["Matricula","Servidor","Cargo","Referência","Remuneração","Abono","Eventuais", "Descontos", "Salario Liquido"])
while (titulo < 18):
apenastag1 = str(apenastag.find_all("td")[titulo].get_text())
apenastag2 = str(apenastag.find_all("td")[atributo].get_text())
#print(apenastag2)
alinhado = alinhado + apenastag2 + ";"
titulo = titulo + 2
atributo = atributo + 2
alinhado = alinhado + "\n"
print(alinhado)
escrevelinha.writerow([alinhado])
The print output is as follows:
Printiscomingoutexactlyasexpected.
TheCSVfilehasonlythelastrecord.
How do I fix this?