Using Python to download a xlsx file from a website using set_preferences

Asked

Viewed 25 times

-1

I’m trying to download a file from a website using Python and I don’t want it to ask me if I want to open or save this file. Follow my code. I haven’t been able to figure out yet, where I’m going wrong.

from selenium import webdriver
import time

browser = webdriver.Firefox()
browser.get('https://www.minhasplanilhas.com.br/planilha-lista-de-tarefas/')

##time.sleep(5)

btns = browser.find_elements_by_xpath("//*[contains(text(), 'Planilha Lista de Tarefas')]") #clica automaticamente para fazer o download da planilha

if len(btns) > 0:
    btns[0].click()

#Para não usar o diretório Downloads padrão
browser.set_preference("browser.download.folderList", 2) 

#Mostra o progresso do Download
browser.set_preference("browser.download.manager.showWhenStarting", False) 

#Define o diretório para downloads

browser.set_preference("browser.download.dir", 'C:Users\nome\Documents') 

#Diz ao navegador para baixar automaticamente os arquivos selecionados
browser.set_preference("browser.helperApps.neverAsk.saveToDisk", "txt/csv/xlsx") 
  • Welcome to [en.so]! You have posted an image of the code and/or error message. Although it sounds like a good idea, it’s not! One of the reasons is that if someone wants to answer the question, they can’t copy the code and change something inside. Click on the [Edit] link and put the code/error as text. See more about this in these links - Manual on how NOT to ask questions, Post Error Message as Picture

No answers

Browser other questions tagged

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