How to set the path to a browser executable with python webbrowser

与世无争的帅哥 提交于 2019-12-23 04:37:07

问题


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(bs4Tag):

    import os
    import webbrowser

    html= str(bs4Tag)

    # html = '<html> ...  generated html string ...</html>'
    path = os.path.abspath('temp.html')
    url = 'file://' + path

    with open(path, 'w') as f:
        f.write(html)
    webbrowser.open(url)
    return

This works great and opens up the HTML in the default browser. However I would like to set the path to a portable firefox executable which is at:

F:\FirefoxPortable\firefox.exe

I am using win7. How to I set the path to the portable firefox executable?


回答1:


You could start your portable Firefox directly with the url as an argument instead.

from subprocess import call
call(["F:\\FirefoxPortable\\firefox.exe", "-new-tab", url])


来源:https://stackoverflow.com/questions/25849813/how-to-set-the-path-to-a-browser-executable-with-python-webbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!