这个硒火狐档案下载文件到自定义文件夹有什么问题? [英] What is wrong with this selenium firefox profile to download file into customized folder?

查看:141
本文介绍了这个硒火狐档案下载文件到自定义文件夹有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用selenium和python v3.6自动化firefox,将文件下载到自定义文件夹中。文件夹的位置是 C:/ Users / username / Dropbox / Inv /

下面是我的firefox 。

$ p $ profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList',2 )#自定义位置
profile.set_preference('browser.download.manager.showWhenStarting',False)
profile.set_preference('browser.download.dir','C:/ Users / username / Dropbox / ('browser.helperApps.neverAsk.saveToDisk','text / plain')
profile.set_preference('browser.helperApps.neverAsk.openFile','text / plain ')

目前,文件总是被下载到默认文件夹 C: \Users\username\Downloads 。我如何获得下载的文件夹位置为 C:/ Users / username / Dropbox / Inv /

解决方案

我会回答我自己的问题。问题在于指定下载目录的字符串。我应该使用 \\ 而不是 /

  profile.set_preference('browser.download.dir','C:\\ Users \\\\\\\\\\\\\\\\'')

代码已被验证正在使用中。


I am using selenium and python v3.6 to automate firefox to download file into a customized folder. The location of the folder is C:/Users/username/Dropbox/Inv/.

Below is my firefox profile.

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', 'C:/Users/username/Dropbox/Inv/')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/plain')
profile.set_preference('browser.helperApps.neverAsk.openFile', 'text/plain')

Currently, the file is always downloaded in the default folder C:\Users\username\Downloads. How do I get the downloaded folder location to be C:/Users/username/Dropbox/Inv/?

解决方案

I will answer my own question. The problem lies with the string specifying the download directory. I should use \\ and not /.

profile.set_preference('browser.download.dir', 'C:\\Users\\username\\Dropbox\\Inv')

The code has been verified to be working now.

这篇关于这个硒火狐档案下载文件到自定义文件夹有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆