2016-09-15 14 views
2

私は、Python 2.7でseleniumの設定これらのFirefoxのプリファレンスを使用しています:セレンPython Selenium:ダウンロード時にファイルを上書きするFirefox set_preference?

ff_profile = webdriver.FirefoxProfile(profile_dir) 

ff_profile.set_preference("browser.download.folderList", 2) 
ff_profile.set_preference("browser.download.manager.showWhenStarting", False) 
ff_profile.set_preference("browser.download.dir", dl_dir) 
ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream") 

を、私はrecurringly同じファイルをダウンロードし、それを上書きし、これと同じファイル名を維持したい - 私は確認することなく、ダウンロード。

上記の設定では、場所を尋ねることなくダウンロードされますが、すべてのダウンロードでは、MacOSではファイル名filename (1).ext,filename (2).extなどを含む重複が作成されます。

私は、Firefox内で上書きを許可して、事故(?)を防ぐ設定がないと思っています。

(その場合、解決策はディスク上の上書きを他のPythonモジュールで処理することだと思います;別のトピック)。

答えて

2

これは、セレンのスコープのうちであり、オペレーティングシステムによって処理されるものです。

この文脈とあなたのprevious questionから判断すると、事前にファイル名を知っている(またはリンクテキストから判断できます)。実際にそうである場合は、「ダウンロード」リンクをクリックする前に、既存のファイルを削除してください:

import os 

filename = "All-tradable-ETFs-ETCs-and-ETNs.xlsx" # or extract it dynamically from the link 
filepath = os.path.join(dl_dir, filename) 
if os.path.exists(filepath): 
    os.remove(filepath) 
関連する問題