我正在尝试构建一个实用函数来将漂亮的汤代码输出到浏览器我有以下代码:
def bs4_to_browser(data):
from selenium import webdriver
driver = webdriver.Firefox(path="F:\FirefoxPortable\Firefox.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
当我运行它时,我得到:
TypeError at /providers/
__init__() got an unexpected keyword argument 'path'
我用的是win7。如何设置可移植 firefox 可执行文件的路径?
最佳答案
要设置 Firefox
的自定义路径,您需要使用 FirefoxBinary
:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('F:\FirefoxPortable\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
或者,或者,将 F:\FirefoxPortable
添加到 PATH
环境变量并以通常的方式启动 Firefox
:
driver = webdriver.Firefox()
关于python - 使用 selenium webdriver 在 Windows 上设置 firefox 二进制文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25713824/