Skip to content

Instantly share code, notes, and snippets.

@DiegoQueiroz
Created May 29, 2015 00:09
Show Gist options
  • Save DiegoQueiroz/04f4f08b07321a7f99d3 to your computer and use it in GitHub Desktop.
Save DiegoQueiroz/04f4f08b07321a7f99d3 to your computer and use it in GitHub Desktop.
Download a single page of CNPq Lattes
# -*- coding: utf-8 -*-
import sys
if sys.version_info.major >= 3:
# usando Python 3.x ou superior
from urllib.request import Request, build_opener, HTTPCookieProcessor
from urllib.parse import urlencode
else:
# usando Python 2.x ou anterior
from urllib2 import Request, build_opener, HTTPCookieProcessor
from urllib import urlencode
url = 'http://buscatextual.cnpq.br/buscatextual/visualizacv.do'
opener = build_opener(HTTPCookieProcessor())
opener.open(url) # esse primeiro acesso serve apenas para criar uma sessão
# e receber as cookies do servidor
# Para cada currículo, é necessário criar uma nova requisição
# e utilizar o Opener para abrir a página
# O mesmo Opener pode ser utilizado para abrir vários currículos
id_curriculo = 'K4212066D0'
data = urlencode({'id' : id_curriculo, 'metodo' : 'visualizarCV'})
data = data.encode('ISO-8859-1') # essencial no Python 3
req = Request(url, data)
pagina = opener.open(req)
print(pagina.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment