相关疑难解决方法(0)

python的webbrowser在Windows 7上启动IE而不是默认

我试图在默认浏览器中从python启动本地html文件.现在我的默认值是谷歌浏览器.如果我双击.html文件,chrome就会启动.

当我使用python的webbrowser.open时,IE会启动,而是使用空白地址栏.

Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> filename = 'test.html'
>>> webbrowser.open('file://'+filename)
True
>>> print(webbrowser.get().__class__.__name__)
WindowsDefault
Run Code Online (Sandbox Code Playgroud)

我检查了我的默认程序,看起来没错.我在Win 7 SP1上.为什么镀铬没有启动?

更新:代码将在未知的操作系统和计算机上运行,​​因此注册浏览器或路径更新不是选项.我正在考虑解析网址file://,然后进行os.path.exists检查,os.path.realpath可能就是答案.

python browser

33
推荐指数
4
解决办法
2万
查看次数

如何在Python中打开浏览器中的HTML文件?

我试图从Python打开一个HTML文件但我的脚本只是用Python显示HTML文件的内容而不是在浏览器中打开它.我该如何解决这个问题?如何在Chrome浏览器中打开HTML文件?

testdata.html

<div>
    <a href="https://plot.ly/user001/2/" target="_blank" title="Success vs Failure" style="display: block; text-align: center;"><img src="https://plot.ly/~user001/2.png" alt="Success vs Failure" style="max-width: 100%;width: 600px;"  width="600" onerror="this.onerror=null;this.src='https://plot.ly/404.png';" /></a>
    <script data-plotly="user001:2"  src="https://plot.ly/embed.js" async></script>
</div>
Run Code Online (Sandbox Code Playgroud)

Python 2.7脚本:

import urllib
page =  urllib.urlopen('testdata.html').read()
print page
Run Code Online (Sandbox Code Playgroud)

html javascript python

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

python ×2

browser ×1

html ×1

javascript ×1