1

In Python 3 I have this code with the use of selenium to automate a search on a site:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('/usr/lib/firefox/firefox')
ff = webdriver.Firefox(firefox_binary=binary)

ff.get('http://www.stf.jus.br/portal/diariojusticaeletronico/pesquisardiarioeletronico.asp#')

ff.find_element_by_id('argumento').send_keys('PPP')

ff.find_element_by_xpath('/html/body/div/div[3]/div[2]/div[2]/div[2]/form/table/tbody/tr[3]/td/input[1]').click()

The code enters the site and searches for the letters "PPP" on the "PESQUISAR" button

The result is a table with links to PDFs. The PDFs I want are in the "Integral" column

Please, is there a way to automatically save each PDF found in the links in the "Integral" column?

Druta Ruslan
  • 7,171
  • 2
  • 28
  • 38
Reinaldo Chaves
  • 965
  • 4
  • 16
  • 43
  • 1
    Possible duplicate of [How can I download a file on a click event using selenium?](https://stackoverflow.com/questions/18439851/how-can-i-download-a-file-on-a-click-event-using-selenium) – JeffC May 23 '18 at 21:55
  • Thank you. With this question I was able to advance more in the solution, but still did not work. I'll post another question. – Reinaldo Chaves May 25 '18 at 15:55

1 Answers1

0

if you want you can use requests, i want to test, but i haven't permission on i try to open link, try this if you have permission, save all links that you need and after that use requests:

import requests
file_url = "http://www.stf.jus.br/portal/diariojusticaeletronico/verDiarioEletronico.asp?seq=14880745&data=23/05/2018&ano=2018&numero=101"

r = requests.get(file_url, stream = True)

with open("x.pdf","wb") as pdf:
    for chunk in r.iter_content(chunk_size=1024):

    # writing one chunk at a time to pdf file
    if chunk:
        pdf.write(chunk)
Druta Ruslan
  • 7,171
  • 2
  • 28
  • 38