我试图建立一个实用程序功能,将漂亮的汤代码输出到浏览器,我有以下代码:
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:
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以通常的方式启动:
F:\FirefoxPortable
PATH
driver = webdriver.Firefox()