使用 selenium webdriver 在 windows 上设置 firefox 二进制文件的路径 [英] Setting path to firefox binary on windows with selenium webdriver
本文介绍了使用 selenium webdriver 在 windows 上设置 firefox 二进制文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建一个实用函数来将漂亮的汤代码输出到浏览器我有以下代码:
I am trying to build a utility function to output beautiful soup code to a browser I have the following code:
def bs4_to_browser(data):
from selenium import webdriver
driver = webdriver.Firefox(path="F:FirefoxPortableFirefox.exe")
driver.get("about:blank")
data = '<h1>test</h1>' # supposed to come from BeautifulSoup
driver.execute_script('document.body.innerHTML = "{html}";'.format(html=data))
return
当我运行这个时,我得到:
when I run this I get:
TypeError at /providers/
__init__() got an unexpected keyword argument 'path'
我用的是win7.如何设置便携式 Firefox 可执行文件的路径?
I am using win7. How to I set the path to the portable firefox executable?
推荐答案
要设置Firefox
的自定义路径,您需要使用FirefoxBinary
:
To set the custom path to Firefox
you need to use FirefoxBinary
:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('F:FirefoxPortableFirefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
或者,或者,将 F:FirefoxPortable
添加到 PATH
环境变量并以通常的方式启动 Firefox
:
Or, alternatively, add F:FirefoxPortable
to the PATH
environment variable and fire up Firefox
in a usual way:
driver = webdriver.Firefox()
这篇关于使用 selenium webdriver 在 windows 上设置 firefox 二进制文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文