我正在尝试通过单击firefox中的按钮来下载某些内容,但一切正常,只是它看起来忽略了下载目录并将所有内容放在Downloads文件夹中。在代码运行的时候,我在firefox上的to testme
clear-all
let counter min-pxcor
while [counter <= max-pxcor]
[ let fn-out (function counter)
if fn-out >= min-pycor and fn-out <= max-pycor
[ ask patch counter fn-out [ set pcolor red]
]
set counter counter + 1
]
end
to-report function [#invalue]
report #invalue ^ 2
end
检查了它,它有我在代码上设置的下载目录,但仍然没有。这是我现在的代码:
about:config
答案 0 :(得分:0)
使用预先定义的 download_directory ,通过Firefox_Profile()
启动新的 GeckoDriver 和 Firefox Quantum客户端会话< Firefox_Profile()
的{em> API文档您有两个选项,如下所示:
您可以在每次新执行时调用新的 Firefox Profile ,并在 Firefox Session 启动期间调用新的 Firefox Profile 如下:
def Firefox_Profile(download_directory):
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.popup_maximum", 0)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", download_directory)
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("privacy.popups.showBrowserMessage", False)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", ".mp3 audio/mpeg")
return profile
#Invoking the _Firefox Profile_
driver = webdriver.Firefox(firefox_profile=profile, executable_path=r'C:\path\to\geckodriver.exe')
或者您可以通过将 Firefox Profile 的绝对路径作为参数传递来调用现有的 Firefox Profile 并调用新的 Firefox Profile < / em>在 Firefox Session 启动期间如下:
def Firefox_Profile(download_directory):
profile = webdriver.FirefoxProfile(r'C:\Users\user_name\AppData\Roaming\Mozilla\Firefox\Profiles\moskcpdq.SeleniumTest')
profile.set_preference("dom.popup_maximum", 0)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", download_directory)
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("privacy.popups.showBrowserMessage", False)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", ".mp3 audio/mpeg")
return profile
#Invoking the _Firefox Profile_
driver = webdriver.Firefox(firefox_profile=profile, executable_path=r'C:\path\to\geckodriver.exe')