Generate pdf file from a pdf object

0

I'm interested in doing crawler to work with pdf , but I hit a doubt here. Home I need to download pdf files from a url in python, when it has a .pdf it's easy and with no problems, but when it's a objeto pdf I can not handle it, I actually do not even find information right how it works .. ..
Ex: link

Does anyone know how I can download this file as a pdf ?

    
asked by anonymous 13.11.2017 / 19:22

1 answer

0

Requests

To get the PDF we can use a library called requests , to install do:

pip install requests

The code looks like this:

import requests

# Url do PDF
url = "http://pesquisa.in.gov.br/imprensa/servlet/INPDFViewer?jornal=529&pagina=1&data=13/11/2017&captchafield=firstAccess"

# Obtém o PDF do link, e guarda na memória
resp = requests.get(url)

# Salva o PDF
with open("diario.pdf", "wb") as code:
    code.write(resp.content)
    
13.11.2017 / 20:09