简体   繁体   English

Python:在浏览器上打开本地 html 文件,而不使用 Webbrowser 或 Selenium

[英]Python : Opening local html file on browser without using Webbrowser or Selenium

I am using a particular version of Python (v 2.7.0) that doesn't allow me to use webbrowser or selenium libraries.我正在使用不允许我使用 webbrowser 或 selenium 库的特定版本的 Python (v 2.7.0)。

It also doesn't recognise os.startfile.它也不识别 os.startfile。

Is there another module to use that allows me to open up a locally addressed html file in my browser?是否有另一个模块可以让我在浏览器中打开本地寻址的 html 文件?

Since you are using windows you can use os.startfile which will start a file with its associated application.由于您使用的是 windows,您可以使用os.startfile来启动一个文件及其关联的应用程序。

>>> import os
>>> os.startfile("PATH_TO_HTML_FILE")

I fumbled on a result by treating it as an exe and project.我通过将其视为 exe 和项目来摸索结果。 Subprocess module worked.子流程模块工作。 Tested a little further and should work for Jython 2.7.0 also.进一步测试,应该也适用于 Jython 2.7.0。

import subprocess as sp
    sp.Popen(["browser_exe_path","html_path"])

Note - if using brave browser - it's exe wasn't recognised.注意 - 如果使用勇敢的浏览器 - 它的 exe 无法识别。 chrome_proxy.exe worked in it's place. chrome_proxy.exe在它的位置工作。

Happy to learn something via feedback.很高兴通过反馈学习一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Webbrowser 锚定在本地 html 文件上 - Python Webbrowser anchors on Local html file 如何在不实际打开浏览器的情况下使用Python向服务器发送URL请求(“不使用webbrowser模块”)? - How can I send a URL request to the server with Python without actually opening my browser (“without using the webbrowser module”)? 使用Selenium WebDriver和Python打开浏览器时出错 - Error in opening browser using selenium webdriver and python Firefox 无法在 selenium python 中使用浏览器打开 - firefox not opening using browser in selenium python 我可以在没有实际浏览器打开python的情况下使用Selenium和Scrapy - Can i use selenium with Scrapy without actual browser opening with python 使用 Gmail API 而不在 Python 中打开浏览器 - Using Gmail API without opening browser in Python 使用 python 和 selenium 打开 Tor 浏览器窗口时,它说缺少 torrc 文件 - when opening a tor browser window using python and selenium, it says torrc file is missing 在本地html文件上评估javascript(无需浏览器) - Evaluate javascript on a local html file (without browser) Python:使用Selenium WebDriver无法在客户端打开浏览器 - Python: browser not opening in client side using Selenium WebDriver 在没有浏览器屏幕的情况下使用 selenium - python windows - using selenium without browser screen - python windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM