Skip to content

Instantly share code, notes, and snippets.

@licensed
Created December 28, 2015 16:36
Show Gist options
  • Save licensed/dceca2cf4b28a25afc59 to your computer and use it in GitHub Desktop.
Save licensed/dceca2cf4b28a25afc59 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import urllib2
print "O arquivo de saida estara no mesmo diretorio da aplicacao e tera o nome eventos.xls \n"
mes = raw_input("Digite o mes em numeral: ")
ano = '2015'
f = open('eventos' + mes + '.xls', 'w')
for dia in range(1,32):
dia = str(dia)
link = "http://www.cecon.pe.gov.br/eventos/?data-tipo=dia&data_inicial=" + dia + "%2F" + mes + "%2F" + ano
p = urllib2.urlopen(link)
conteudo = BeautifulSoup(p.read())
ev = conteudo.findAll('span', attrs={'class' : 'evento-nome'})
for evento in ev:
f.write(dia + '/' + mes + '/' + ano + '\t' + evento.string.encode('utf-8') + '\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment