3

私はこのコードを使用して、プロンプトなしでWinzipファイルをダウンロードするフローを自動化します。しかし、それは機能していないようです

profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',("application/zip,
                                                   application/octet-stream"))
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', '/home/jack/DOWNLOAD')
self.driver = webdriver.Firefox(firefox_profile=profile)

自動化中にダイアログボックスが開いたままになっています。

4

1 に答える 1

3

hrefダウンロードリンクを抽出し、Pythonurllibモジュールを使用することで、この状況を解決しました。

以下のコードを使用して、ファイルをダウンロードし、別のファイル名で保存することもできます。

import urllib
url = driver.find_element_by_link_text("Download").get_attribute("href");
urllib.urlretrieve(url, "saveasfilename") 
于 2012-12-05T06:37:35.687 に答える