开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.7.4
/
Doc
/
library
/
webbrowser.rst
python3.7.4
/
Doc
/
library
/
webbrowser.rst
webbrowser.rst 9.78 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月17日 13:49 +08:00 . git init

:mod:`webbrowser` --- Convenient Web-browser controller

.. module:: webbrowser
 :synopsis: Easy-to-use controller for Web browsers.

.. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>

Source code: :source:`Lib/webbrowser.py`


The :mod:`webbrowser` module provides a high-level interface to allow displaying Web-based documents to users. Under most circumstances, simply calling the :func:`.open` function from this module will do the right thing.

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.

If the environment variable :envvar:`BROWSER` exists, it is interpreted as the :data:`os.pathsep`-separated list of browsers to try ahead of 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]

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.

The script :program:`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 "http://www.python.org"

The following exception is defined:

.. exception:: Error

 Exception raised when a browser control error occurs.

The following functions are defined:

.. function:: 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).

 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.


.. function:: open_new(url)

 Open *url* in a new window of the default browser, if possible, otherwise, open
 *url* in the only browser window.

.. function:: open_new_tab(url)

 Open *url* in a new page ("tab") of the default browser, if possible, otherwise
 equivalent to :func:`open_new`.


.. function:: 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.


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

 Register the browser type *name*. Once a browser type is registered, the
 :func:`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``.

 Setting *preferred* to ``True`` makes this browser a preferred result for
 a :func:`get` call with no argument. Otherwise, this entry point is only
 useful if you plan to either set the :envvar:`BROWSER` variable or call
 :func:`get` with a nonempty argument matching the name of a handler you
 declare.

 .. versionchanged:: 3.7
 *preferred* keyword-only parameter was added.

A number of browser types are predefined. This table gives the type names that may be passed to the :func:`get` function and the corresponding instantiations for the controller classes, all defined in this module.

Type Name Class Name Notes
'mozilla' :class:`Mozilla('mozilla')`
'firefox' :class:`Mozilla('mozilla')`
'netscape' :class:`Mozilla('netscape')`
'galeon' :class:`Galeon('galeon')`
'epiphany' :class:`Galeon('epiphany')`
'skipstone' :class:`BackgroundBrowser('skipstone')`
'kfmclient' :class:`Konqueror()` (1)
'konqueror' :class:`Konqueror()` (1)
'kfm' :class:`Konqueror()` (1)
'mosaic' :class:`BackgroundBrowser('mosaic')`
'opera' :class:`Opera()`
'grail' :class:`Grail()`
'links' :class:`GenericBrowser('links')`
'elinks' :class:`Elinks('elinks')`
'lynx' :class:`GenericBrowser('lynx')`
'w3m' :class:`GenericBrowser('w3m')`
'windows-default' :class:`WindowsDefault` (2)
'macosx' :class:`MacOSX('default')` (3)
'safari' :class:`MacOSX('safari')` (3)
'google-chrome' :class:`Chrome('google-chrome')`
'chrome' :class:`Chrome('chrome')`
'chromium' :class:`Chromium('chromium')`
'chromium-browser' :class:`Chromium('chromium-browser')`

Notes:

  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 :envvar:`KDEDIR` variable is not sufficient. Note also that the name "kfm" is used even when using the :program:`konqueror` command with KDE 2 --- the implementation selects the best strategy for running Konqueror.
  2. Only on Windows platforms.
  3. Only on Mac OS X platform.
.. versionadded:: 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)

Browser Controller Objects

Browser controllers provide these methods which parallel three of the module-level convenience functions:

.. method:: 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.


.. method:: 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
 :func:`open_new`.


.. method:: controller.open_new_tab(url)

 Open *url* in a new page ("tab") of the browser handled by this controller, if
 possible, otherwise equivalent to :func:`open_new`.


Footnotes

[1] Executables named here without a full path will be searched in the directories given in the :envvar:`PATH` environment variable.
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.7.4.git
git@gitee.com:python_sourcecode/python3.7.4.git
python_sourcecode
python3.7.4
python3.7.4
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /