"webbrowser" --- 方便的 Web 浏览器控制工具
******************************************

**源码：** Lib/webbrowser.py

======================================================================

"webbrowser" 模块提供了一个高层级接口，允许向用户显示基于 Web 的文档。
在大多数情况下，只需调用此模块的 "open()" 函数就可以了。

在 Unix 下，图形浏览器在 X11 下是首选，但如果图形浏览器不可用或 X11 显
示不可用，则将使用文本模式浏览器。 如果使用文本模式浏览器，则调用进程
将阻塞，直到用户退出浏览器。

如果存在环境变量 "BROWSER" ，则将其解释为 "os.pathsep" 分隔的浏览器列
表，以便在平台默认值之前尝试。 当列表部分的值包含字符串 "％s" 时，它被
解释为一个文字浏览器命令行，用于替换 "％s" 的参数 URL ；如果该部分不包
含 "％s"，则它只被解释为要启动的浏览器的名称。 [1]

对于非 Unix 平台，或者当 Unix 上有远程浏览器时，控制过程不会等待用户完
成浏览器，而是允许远程浏览器在显示界面上维护自己的窗口。 如果 Unix 上
没有远程浏览器，控制进程将启动一个新的浏览器并等待。

The script **webbrowser** can be used as a command-line interface for
the module. It accepts a 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:

   python -m webbrowser -t "https://www.python.org"

可用性: 非 Emscripten，非 WASI。

此模块在 WebAssembly 平台 "wasm32-emscripten" 和 "wasm32-wasi" 上不适
用或不可用。 请参阅 WebAssembly 平台 了解详情。

定义了以下异常：

exception webbrowser.Error

   发生浏览器控件错误时引发异常。

定义了以下函数：

webbrowser.open(url, new=0, autoraise=True)

   使用默认浏览器显示 *url*。 如果 *new* 为 0，则尽可能在同一浏览器窗
   口中打开 *url*。 如果 *new* 为 1，则尽可能打开新的浏览器窗口。 如果
   *new* 为 2，则尽可能打开新的浏览器页面（“标签”）。 如果 *autoraise*
   为 “True”，则会尽可能置前窗口（请注意，在许多窗口管理器下，无论此变
   量的设置如何，都会置前窗口）。

   请注意，在某些平台上，尝试使用此函数打开文件名，可能会起作用并启动
   操作系统的关联程序。 但是，这种方式不被支持也不可移植。

   使用 "url" 参数会引发  auditing event "webbrowser.open" 。

webbrowser.open_new(url)

   如果可能，在默认浏览器的新窗口中打开 *url*，否则，在唯一的浏览器窗
   口中打开 *url*。

webbrowser.open_new_tab(url)

   如果可能，在默认浏览器的新页面（“标签”）中打开 *url*，否则等效于
   "open_new()"。

webbrowser.get(using=None)

   返回浏览器类型为 *using* 指定的控制器对象。 如果 *using* 为 "None"
   ，则返回适用于调用者环境的默认浏览器的控制器。

webbrowser.register(name, constructor, instance=None, *, preferred=False)

   注册 *name* 浏览器类型。 注册浏览器类型后， "get()" 函数可以返回该
   浏览器类型的控制器。 如果没有提供 *instance*，或者为 "None"，
   *constructor* 将在没有参数的情况下被调用，以在需要时创建实例。 如果
   提供了 *instance*，则永远不会调用 *constructor*，并且可能是 "None"
   。

   将 *preferred* 设置为 "True" 使得这个浏览器成为 "get()" 不带参数调
   用的首选结果。 否则，只有在您计划设置 "BROWSER" 变量，或使用与您声
   明的处理程序的名称相匹配的非空参数调用 "get()" 时，此入口点才有用。

   在 3.7 版本发生变更: 添加了仅关键字参数 *preferred*。

预定义了许多浏览器类型。 此表给出了可以传递给 "get()" 函数的类型名称以
及控制器类的相应实例化，这些都在此模块中定义。

+--------------------------+-------------------------------------------+---------+
| 类型名                   | 类名                                      | 备注    |
|==========================|===========================================|=========|
| "'mozilla'"              | "Mozilla('mozilla')"                      |         |
+--------------------------+-------------------------------------------+---------+
| "'firefox'"              | "Mozilla('mozilla')"                      |         |
+--------------------------+-------------------------------------------+---------+
| "'epiphany'"             | "Epiphany('epiphany')"                    |         |
+--------------------------+-------------------------------------------+---------+
| "'kfmclient'"            | "Konqueror()"                             | (1)     |
+--------------------------+-------------------------------------------+---------+
| "'konqueror'"            | "Konqueror()"                             | (1)     |
+--------------------------+-------------------------------------------+---------+
| "'kfm'"                  | "Konqueror()"                             | (1)     |
+--------------------------+-------------------------------------------+---------+
| "'opera'"                | "Opera()"                                 |         |
+--------------------------+-------------------------------------------+---------+
| "'links'"                | "GenericBrowser('links')"                 |         |
+--------------------------+-------------------------------------------+---------+
| "'elinks'"               | "Elinks('elinks')"                        |         |
+--------------------------+-------------------------------------------+---------+
| "'lynx'"                 | "GenericBrowser('lynx')"                  |         |
+--------------------------+-------------------------------------------+---------+
| "'w3m'"                  | "GenericBrowser('w3m')"                   |         |
+--------------------------+-------------------------------------------+---------+
| "'windows-default'"      | "WindowsDefault"                          | (2)     |
+--------------------------+-------------------------------------------+---------+
| "'macosx'"               | "MacOSXOSAScript('default')"              | (3)     |
+--------------------------+-------------------------------------------+---------+
| "'safari'"               | "MacOSXOSAScript('safari')"               | (3)     |
+--------------------------+-------------------------------------------+---------+
| "'google-chrome'"        | "Chrome('google-chrome')"                 |         |
+--------------------------+-------------------------------------------+---------+
| "'chrome'"               | "Chrome('chrome')"                        |         |
+--------------------------+-------------------------------------------+---------+
| "'chromium'"             | "Chromium('chromium')"                    |         |
+--------------------------+-------------------------------------------+---------+
| "'chromium-browser'"     | "Chromium('chromium-browser')"            |         |
+--------------------------+-------------------------------------------+---------+

注释：

1. "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.

2. 仅限 Windows 平台。

3. Only on macOS platform.

Added in version 3.3: 添加了对 Chrome/Chromium 的支持。

在 3.12 版本发生变更: 对某些过时浏览器的支持已被移除。 被移除的浏览器
包括 Grail, Mosaic, Netscape, Galeon, Skipstone, Iceape 和 Firefox 35
及以下的版本。

从 3.11 版起不建议使用，将在 3.13 版中移除: "MacOSX" is deprecated,
use "MacOSXOSAScript" instead.

以下是一些简单的例子:

   url = 'https://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)


浏览器控制器对象
================

浏览器控制器提供三个与模块级便捷函数相同的方法：

webbrowser.name

   浏览器依赖于系统的名称。

controller.open(url, new=0, autoraise=True)

   使用此控制器处理的浏览器显示 *url*。 如果 *new* 为 1，则尽可能打开
   新的浏览器窗口。 如果 *new* 为 2，则尽可能打开新的浏览器页面（“标签
   ”）。

controller.open_new(url)

   如果可能，在此控制器处理的浏览器的新窗口中打开 *url* ，否则，在唯一
   的浏览器窗口中打开 *url* 。 别名 "open_new()"。

controller.open_new_tab(url)

   如果可能，在此控制器处理的浏览器的新页面（“标签”）中打开 *url*，否
   则等效于 "open_new()"。

-[ 备注 ]-

[1] 这里命名的不带完整路径的可执行文件将在 "PATH" 环境变量给出的目录中
    搜索。
