How to set the path to a browser executable with p

2019-06-12 05:31发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-12 06:00

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])
查看更多
登录 后发表回答