在Python Selenium中为Firefox设置配置文件和二进制文件不会打开浏览器

2024-09-28 16:19:25 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所说,当我设置一个配置文件和二进制文件,然后将它们输入webdriver.Firefox时,没有浏览器是打开的。我找了好几个小时,没有找到解决这个问题的办法。任何帮助都将不胜感激

我尝试过的代码:

binary = FirefoxBinary("D:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = FirefoxProfile("D:\\SYC\\fireFox\\Project\\lp5w3va5.PythonBot")
driver = webdriver.Firefox(profile, binary)
binary = FirefoxBinary("D:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = FirefoxProfile("D:\\SYC\\fireFox\\Project\\lp5w3va5.PythonBot")
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)
binary = FirefoxBinary("D:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = FirefoxProfile("D:\\SYC\\fireFox\\Project\\lp5w3va5.PythonBot")
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="D:\\Python\\geckodriver.exe")

运行此代码(即使使用driver.get)也不会显示任何webbrowser。编译此代码时,我没有收到任何错误。老实说,我一直在想怎样才能让它发挥作用

driver = webdriver.Firefox()

将使用无设置的临时配置文件启动浏览器(每次运行脚本时,都会创建不同的临时配置文件)

你知道为什么会这样吗

编辑:为了澄清,我在python文件夹中安装了geckodriver。使用配置文件运行web浏览器效果非常好

编辑:解决了。问题是将配置文件放在我的D:drive中创建了一个远程目录,但我需要一个本地目录。我必须把我的个人资料和我的其他个人资料放在我的C:驱动器中


Tags: 代码mozilla配置文件driver浏览器filesfirefoxprofile