cesar rivas
cesar rivas

Reputation: 23

Problem download pdf files with python + selenium

I need your help, I am trying to automate the download of PDF files with selenium webdriver in python, this code when executed brings me the download links and prints them in console but I need them to be downloaded and saved locally in My PC.

I use ubuntu 18.04 as a development environment in python 3x. Thank you

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as W
from selenium.webdriver.support import expected_conditions as E

URL = "https://www.diariooficial.interior.gob.cl/edicionelectronica/marcas_patentes.php?date=19-06-2020&edition=42685"



wait_time_out = 15
driver = webdriver.Chrome('./chromedriver')
driver.get(URL)
wait_variable = W(driver, wait_time_out)
links = wait_variable.until(E.visibility_of_all_elements_located((By.TAG_NAME, "a")))
print("Numero de links", len(links))
for link in links:
    print(link.text)

Upvotes: 1

Views: 1221

Answers (1)

Nivardo Albuquerque
Nivardo Albuquerque

Reputation: 536

There are a lot of posts about that same issue.

In this(Selenium Webdriver in Python - files download directory change in Chrome preferences) one, there is a fix, where you change the default download location.

Also, have in mind that you may need to implement a routine to wait for downloads to finish(if you are downloading large files).

Hope it helps.

Upvotes: 2

Related Questions