Python标准库3.4.3-webbrowser-21.1
21.1. webbrowser — Convenient Web-browser controller
Source code: Lib/webbrowser.py 翻译:Z.F.
The webbrowser module provides a high-level interface to allow displaying Web-based documents to users. Under most circumstances, simply calling the open() function from this module will do the right thing.
webbrowser模块提供一个高阶的接口来为用户显示基于web的文档,在大多数情况下,简单的调用open()函数就可以正常的工作。
Under Unix, graphical browsers are preferred under X11, but text-mode browsers will be used if graphical browsers are not available or an X11 display isn’t available. If text-mode browsers are used, the calling process will block until the user exits the browser.
在Unix环境中,图形化的浏览器有更高的优先级在X11环境中,如果图形化的浏览器不可用,或者X11图形显示不可用,则使用文本模式的浏览器。如果使用文本模式的浏览器,则调用进程是阻塞的,直到用户退出。
If the environment variable BROWSER exists, it is interpreted as the os.pathsep-separated list of browsers to try ahead of the the platform defaults. When the value of a list part contains the string %s, then it is interpreted as a literal browser command line to be used with the argument URL substituted for %s; if the part does not contain %s, it is simply interpreted as the name of the browser to launch. [1]
如果有环境变量 BROWSER,它被解释为os.pathsep分割的浏览器列表,并处于系统默认值之前,当列表的值之中含有字符串%s时,它将被解释为一个字面的浏览器命令,并使用url参数代替%s,如果不包含%s,则简单的解释为要使用的浏览器的名字。
For non-Unix platforms, or when a remote browser is available on Unix, the controlling process will not wait for the user to finish with the browser, but allow the remote browser to maintain its own windows on the display. If remote browsers are not available on Unix, the controlling process will launch a new browser and wait。
对于非Unix平台,或者一个UNIX下可用的远程浏览器 ,管理进程将不等待用户的浏览器结束,但是允许远程的浏览器保持她自己的窗口显示。如果远程浏览器在Unix系统不可用,管理进程将载入一个新的浏览器并等待。
The script webbrowser can be used as a command-line interface for the module. It accepts an URL as the argument. It accepts the following optional parameters: -n opens the URL in a new browser window, if possible; -t opens the URL in a new browser page (“tab”). The options are, naturally, mutually exclusive. Usage example:
webbrowser可以作为该模块一个命令行接口来使用,它接受一个URL作为参数,-n 在一个新窗口中打开url,如果有可能,-t将在一个新的标签页打开该url,2个选项是互斥的。 例如:
python -m webbrowser -t "http://www.python.org"
The following exception is defined:
- exception webbrowser.Error
-
Exception raised when a browser control error occurs.
The following functions are defined:
- webbrowser.open(url, new=0, autoraise=True)
-
Display url using the default browser. If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible. If autoraise is True, the window is raised if possible (note that under many window managers this will occur regardless of the setting of this variable).
使用默认的浏览器显示这个URL,如果参数new是0,url将在同一个浏览器窗口中被打开,如果new是1,将打开一个新的浏览器窗口来加载该url,如果new是2,则在一个新的标签页中打开。 如果autoraise被设置为true,则窗口将被自动激活。(请注意:有许多窗口管理器将直接忽略该变量的设置)
Note that on some platforms, trying to open a filename using this function, may work and start the operating system’s associated program. However, this is neither supported nor portable.
在一些平台下,如果试图通过该函数来打开一个文件名,将启动操作系统默认的程序来打开。 但是,这种方法是不被支持和不易于移植的。
- webbrowser.open_new(url)
-
Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.
新开一个默认浏览器窗口,打开ur,l否则,仅仅是在一个浏览器窗口中打开url.
- webbrowser.open_new_tab(url)
-
Open url in a new page (“tab”) of the default browser, if possible, otherwise equivalent to open_new().
- webbrowser.get(using=None)
-
Return a controller object for the browser type using. If using is None, return a controller for a default browser appropriate to the caller’s environment.
返回一个特定浏览器类型的控制对象。如果使用None, 返回一个合乎调用者环境的默认的浏览器对象。
- webbrowser.register(name, constructor, instance=None)
-
Register the browser type name. Once a browser type is registered, the get() function can return a controller for that browser type. If instance is not provided, or is None, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be None.
注册浏览器类型名。当一个浏览器类型被注册, get()函数将返回一个该浏览器类型的控制器。如果instance参数没有被提供,或者是None,constructor将在需要的时候被无参数调用来创建一个实例。如果instance被提供了,则constructor将永不会被调用,或者被设置为None。
This entry point is only useful if you plan to either set the BROWSER variable or call get() with a nonempty argument matching the name of a handler you declare.
这个入口函数仅仅在你设置 BROWSER 变量 或者用非空的你自己声明的处理函数做参数,调用 get()时有用。
A number of browser types are predefined. This table gives the type names that may be passed to the get() function and the corresponding instantiations for the controller classes, all defined in this module.
若干浏览器类型已经被预先定义。下面这个表给出了可以传递给 get()函数的类型名字和相应实例的类名。所有的这些,都在此模块中定义过了。
| Type Name | Class Name | Notes |
|---|---|---|
| 'mozilla' | Mozilla('mozilla') | |
| 'firefox' | Mozilla('mozilla') | |
| 'netscape' | Mozilla('netscape') | |
| 'galeon' | Galeon('galeon') | |
| 'epiphany' | Galeon('epiphany') | |
| 'skipstone' | BackgroundBrowser('skipstone') | |
| 'kfmclient' | Konqueror() | (1) |
| 'konqueror' | Konqueror() | (1) |
| 'kfm' | Konqueror() | (1) |
| 'mosaic' | BackgroundBrowser('mosaic') | |
| 'opera' | Opera() | |
| 'grail' | Grail() | |
| 'links' | GenericBrowser('links') | |
| 'elinks' | Elinks('elinks') | |
| 'lynx' | GenericBrowser('lynx') | |
| 'w3m' | GenericBrowser('w3m') | |
| 'windows-default' | WindowsDefault | (2) |
| 'macosx' | MacOSX('default') | (3) |
| 'safari' | MacOSX('safari') | (3) |
| 'google-chrome' | Chrome('google-chrome') | |
| 'chrome' | Chrome('chrome') | |
| 'chromium' | Chromium('chromium') | |
| 'chromium-browser' | Chromium('chromium-browser') |
Notes:
- “Konqueror” is the file manager for the KDE desktop environment for Unix, and only makes sense to use if KDE is running. Some way of reliably detecting KDE would be nice; the KDEDIR variable is not sufficient. Note also that the name “kfm” is used even when using the konqueror command with KDE 2 — the implementation selects the best strategy for running Konqueror.
- Only on Windows platforms.
- Only on Mac OS X platform.
New in version 3.3: Support for Chrome/Chromium has been added.
Here are some simple examples:
url = 'http://docs.python.org/' # Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url) # Open URL in new window, raising the window if possible.
webbrowser.open_new(url)
21.1.1. Browser Controller Objects
Browser controllers provide these methods which parallel three of the module-level convenience functions:
- controller.open(url, new=0, autoraise=True)
-
Display url using the browser handled by this controller. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible.
- controller.open_new(url)
-
Open url in a new window of the browser handled by this controller, if possible, otherwise, open url in the only browser window. Alias open_new().
- controller.open_new_tab(url)
-
Open url in a new page (“tab”) of the browser handled by this controller, if possible, otherwise equivalent to open_new().
Footnotes
| [1] |
Executables named here without a full path will be searched in the directories given in the PATH environment variable. |
Python标准库3.4.3-webbrowser-21.1的更多相关文章
- python第六天 函数 python标准库实例大全
今天学习第一模块的最后一课课程--函数: python的第一个函数: 1 def func1(): 2 print('第一个函数') 3 return 0 4 func1() 1 同时返回多种类型时, ...
- Python 标准库一览(Python进阶学习)
转自:http://blog.csdn.net/jurbo/article/details/52334345 写这个的起因是,还是因为在做Python challenge的时候,有的时候想解决问题,连 ...
- 转--Python标准库之一句话概括
作者原文链接 想掌握Python标准库,读它的官方文档很重要.本文并非此文档的复制版,而是对每一个库的一句话概括以及它的主要函数,由此用什么库心里就会有数了. 文本处理 string: 提供了字符集: ...
- python 标准库大全
python 标准库 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata:Unicode字符数据库 string ...
- Python标准库、第三方库和外部工具汇总
导读:Python数据工具箱涵盖从数据源到数据可视化的完整流程中涉及到的常用库.函数和外部工具.其中既有Python内置函数和标准库,又有第三方库和工具. 这些库可用于文件读写.网络抓取和解析.数据连 ...
- 140种Python标准库、第三方库和外部工具
导读:Python数据工具箱涵盖从数据源到数据可视化的完整流程中涉及到的常用库.函数和外部工具.其中既有Python内置函数和标准库,又有第三方库和工具. 这些库可用于文件读写.网络抓取和解析.数据连 ...
- Python标准库14 数据库 (sqlite3)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python自带一个轻量级的关系型数据库SQLite.这一数据库使用SQL语言.S ...
- python标准库00 学习准备
Python标准库----走马观花 python有一套很有用的标准库.标准库会随着python解释器一起安装在你的电脑上的.它是python的一个组成部分.这些标准库是python为你准备的利器,可以 ...
- Python标准库:内置函数hasattr(object, name)
Python标准库:内置函数hasattr(object, name) 本函数是用来判断对象object的属性(name表示)是否存在.如果属性(name表示)存在,则返回True,否则返回False ...
- python标准库xml.etree.ElementTree的bug
使用python生成或者解析xml的方法用的最多的可能就数python标准库xml.etree.ElementTree和lxml了,在某些环境下使用xml.etree.ElementTree更方便一些 ...
随机推荐
- (十四)访问标志 Access_flags
一.概念 上一章节讲到了常量池,如下图,常量池之后便是访问标志acess_flags,占2个字节(u2). 二.例子 编写一个接口. public interface Test{ public fin ...
- css文本超出部分省略号&CSS强制换行总结
word-break:break-all单词截断自动换行 word-break:break-all 例如div宽200px,它的内容就会到200px自动换行,如果该行末端有个英文单词很长(congra ...
- windows系统中在jupyter安装虚拟环境内核
一.在jupyter中安装虚拟环境内核 1.创建Python3虚拟环境 参考本文其他博客 2.进入虚拟环境 3.安装jupyter pip install jupyter 4.添加当前环境到jupyt ...
- 学习开始记录一下,java 还是python?
2019.11.24开始正式开始学习JAVA. 在 bilibili站看了三天,大神们的对此问题的分析,介绍,我选择了JAVA开发语言. 在看了高淇老师的JAVA300视频,感觉比较对路,特别是第一章 ...
- git将代码提交到多个远程仓库
在项目目录下执行: git remote set-url --add origin http://mayun.cn/xxx/adsdsdsdcelery-demo.git 即可添加一个远程仓库. 再执 ...
- 玫瑰花小制作分享-JavaScript(七夕专属浪漫)
分享一个玫瑰花的制作小方法,用小小的代码给自己的她送上一个不一样的玫瑰花. 玫瑰花代码由JavaScript实现,JavaScript 作为一种脚本语言, 被发明用于在 HTML 网页上使用,可以给H ...
- Python进阶:metaclass谈
metaclass 的超越变形特性有什么用? 来看yaml的实例: import yaml class Monster(yaml.YAMLObject): yaml_tag = u'!Monster' ...
- c++ (1) c++ 与c 的区别
可以说c++ 语言在c基础上扩展了许多 在学习玩c语言之后 学习c++ 会发现容易一些 但是c++也有优越于c 的地方 c++ 与c 语言都属于本地编译型语言 ,直接编译成本地编译码,运行特别快 ...
- go语言的安装及环境配置
Go语言开发环境搭建(ubuntu) 1.清理.卸载之前的 go 语言环境: 删除go目录:sudo rm -rf /usr/local/go 删除软链接(如果建立了软链接):sudo rm -rf ...
- python3 内置方法 字符串转换为字典
内置方法:eval()将字符串转换为字典代码: str = '''{'backend':'www.oldboy.org', 'record':{ 'server':'122.111.2.23', 'w ...