使用到的模块webbrowser,它也就这一个功能。
1 2 3 4 5 6 7 8 9 10 11 12 |
import webbrowser webbrowser.open('https://www.google.com') # 使用新窗口、新标签页打开 webbrowser.open_new('https://www.github.com') webbrowser.open_new_tab('https://www.github.com') # 指定使用的浏览器 # b = webbrowser.get('lynx') # b.open('https://www.google.com') # 或使用环境变量 $ BROWSER=lynx python3 webbrowser_open.py |
webbrowser的命令行接口:
1 2 3 4 5 |
$ python3 -m webbrowser Usage: .../lib/python3.5/webbrowser.py [-n | -t] url -n: open new window -t: open new tab |
- webbrowser文档:https://docs.python.org/3/library/webbrowser.html