Created
May 22, 2019 06:59
-
-
Save edsion1107/93c82e2a38f306aa7e7d9a12c56764e4 to your computer and use it in GitHub Desktop.
通过python调用浏览器,打开一个本地html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
@author: edsion | |
@file: demo.py | |
@time: 2019-05-22 14:50 | |
当前工程目录结构: | |
. | |
├── allure-report_1108126771 | |
│ ├── app.js | |
│ ├── data | |
│ ├── export | |
│ ├── favicon.ico | |
│ ├── history | |
│ ├── index.html | |
│ ├── plugins | |
│ ├── styles.css | |
│ └── widgets | |
├── demo.py | |
""" | |
import os | |
import webbrowser | |
from threading import Thread | |
from pathlib import Path | |
from http.server import test, SimpleHTTPRequestHandler | |
os.chdir(Path('allure-report_1108126771')) | |
Thread(target=test, kwargs={'HandlerClass': SimpleHTTPRequestHandler}).start() | |
# time.sleep(3) # http server启动需要一点时间 | |
webbrowser.get('chrome').open('http://localhost:8000/index.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如果是python3.7,可以指定
--directory
参数,从而省略os.chdir()