如何将路径设置为浏览器可执行文件与网页浏览器蟒 [英] How to set the path to a browser executable with python webbrowser

查看:353
本文介绍了如何将路径设置为浏览器可执行文件与网页浏览器蟒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个效用函数输出美丽的汤code到浏览器我有以下code:

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

这个伟大的工程,开辟了在默认浏览器的HTML。不过,我想的路径设置为一个便携Firefox的可执行文件,在

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

我使用的win7。如何我的路径设置为便携Firefox的可执行文件?

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

推荐答案

您可以直接与URL作为参数来启动,而不是您的便携式Firefox浏览器。

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])

这篇关于如何将路径设置为浏览器可执行文件与网页浏览器蟒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆