简体   繁体   中英

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.

It also doesn't recognise os.startfile.

Is there another module to use that allows me to open up a locally addressed html file in my browser?

Since you are using windows you can use os.startfile which will start a file with its associated application.

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

I fumbled on a result by treating it as an exe and project. Subprocess module worked. Tested a little further and should work for Jython 2.7.0 also.

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

Note - if using brave browser - it's exe wasn't recognised. chrome_proxy.exe worked in it's place.

Happy to learn something via feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM