I'm having difficulty finalizing a crawler (more specifically in the output file in txt). It must have a header (h), and a footer (p) that should be written only once. And variable data (col) that will be generated by Scrapy. Currently I have included the header and footer manually and I'm looking for a way to automate the process. I know that the plain text file does not have a header and a footer. But is there any way to simulate this without having to resort to external modules?
filename = item['cat'] + '.txt'
f= open(filename,'a')
h = ('As últimas notícias')
p = ('Você só encontra aqui')
col = ('item['title'] \n + item ['author']\n + item['img']\n\n+ item['news']')
f.write('h \n + col \n + p')
f.close()
Desired output:
As últimas notícias
title here
author here
img link here
news here
title here
author here
img link here
news here
title here
author here
img link here
news here
title here
author here
img link here
news here
Você só encontra aqui