Generate pdf file from a pdf Object

Asked

Viewed 305 times

1

  • What version of python do you use?

1 answer

2

Requests

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

pip install requests

The code will look 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)
  • I can’t believe it was that simple

  • Not at all. If you found the answer helpful just vote in favor, and it’s the right one for you, mark it as correct. Welcome to Sopt!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.