使用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:\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
运行此命令时,我得到:
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:\FirefoxPortable\Firefox.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屋!
查看全文