Ton*_*Joe 5 python selenium 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)
这是正确的方法还是我错过了什么?
以下是创建新配置文件并使用现有配置文件启动 Firefox 的手动过程:
要创建新的配置文件,请执行命令:firefox.exe -CreateProfile JoelUser
要在另一个目录中创建新的配置文件,请执行命令:firefox.exe -CreateProfile "JoelUser c:\internet\joelusers-moz-profile"
要使用新配置文件启动 Firefox,请执行命令:firefox.exe -P "Joel User"
现在,为了以编程方式实现相同的目标,我找到了该步骤。1 或 2 可以使用子进程和步骤号来执行。3可以通过以下方式实现/sf/answers/3784561651/
参考:
firefox bug - 无法使用自定义配置文件创建新会话:https://github.com/mozilla/geckodriver/issues/1058
https://bugzilla.mozilla.org/show_bug.cgi?id=1421766
Firefox 命令行参数 - https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#user_profile
子流程 api 文档 - https://docs.python.org/3/library/subprocess.html
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |