相关疑难解决方法(0)

如何使用Python + Selenium WebDriver保存和加载cookie

如何将Python的Selenium WebDriver中的所有cookie保存到txt文件中,然后再加载它们?该文档没有说明getCookies函数的任何内容.

python selenium webdriver

78
推荐指数
6
解决办法
9万
查看次数

如何在 python 中保存 Firefox webdriver 会话

为了保存 chromedriver 会话,我使用了以下代码片段:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Chrome(executable_path='path to chromedriver.exe', chrome_options=options)
Run Code Online (Sandbox Code Playgroud)

我尝试用 Firefox 做同样的事情,但似乎不起作用:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Firefox(executable_path='path to geckodriver.exe', firefox_options=options)
Run Code Online (Sandbox Code Playgroud)

这是正确的方法还是我错过了什么?

python selenium webdriver

5
推荐指数
1
解决办法
1848
查看次数

如何使用 selenium / firefox / python 切换下载目录?

我知道以前有人问过这个问题……但我尝试了多种方法,出于某种原因,我从驱动程序下载的任何内容都会进入我的下载文件夹。

基本上我导航到一个网站并通过点击下载链接下载一些东西,如下所示:

result.click()
Run Code Online (Sandbox Code Playgroud)

这可以很好地下载文件。但我想将其下载到特定目录。我尝试使用这些方法来更改下载目录:

driver = webdriver.Firefox()
profile = webdriver.FirefoxProfile()

driver.command_executor._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context")
driver.execute("SET_CONTEXT", {"context": "chrome"})
driver.execute_script("""
  Services.prefs.setBoolPref('browser.download.useDownloadDir', true);
  Services.prefs.setStringPref('browser.download.dir', arguments[0]);
  """, directory)

driver.execute("SET_CONTEXT", {"context": "content"})
Run Code Online (Sandbox Code Playgroud)

profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", directory)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
Run Code Online (Sandbox Code Playgroud)

directory我想要的位置在哪里。

这些都不起作用......谁能解释为什么或告诉我如何实际实现这一目标?

谢谢

python firefox selenium

5
推荐指数
3
解决办法
4737
查看次数

标签 统计

python ×3

selenium ×3

webdriver ×2

firefox ×1