Skip to content

Commit d3226fb

Browse files
committed
13.15小节完成,13章完成
1 parent bd0b2f8 commit d3226fb

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

source/c13/p15_luanch_a_web_browser.rst

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,58 @@
55
----------
66
问题
77
----------
8-
You want to launch a browser from a script and have it point to some URL that you
9-
specify.
8+
你想通过脚本启动浏览器并打开指定的URL网页
109

1110
|
1211
1312
----------
1413
解决方案
1514
----------
16-
The webbrowser module can be used to launch a browser in a platform-independent
17-
manner. For example:
15+
``webbrowser`` 模块能被用来启动一个浏览器,并且与平台无关。例如:
1816

19-
>>> import webbrowser
20-
>>> webbrowser.open('http://www.python.org')
21-
True
22-
>>>
17+
.. code-block:: python
2318
24-
This opens the requested page using the default browser. If you want a bit more control
25-
over how the page gets opened, you can use one of the following functions:
19+
>>> import webbrowser
20+
>>> webbrowser.open('http://www.python.org')
21+
True
22+
>>>
2623
27-
>>> # Open the page in a new browser window
28-
>>> webbrowser.open_new('http://www.python.org')
29-
True
30-
>>>
24+
它会使用默认浏览器打开指定网页。如果你还想对网页打开方式做更多控制,还可以使用下面这些函数:
3125

32-
>>> # Open the page in a new browser tab
33-
>>> webbrowser.open_new_tab('http://www.python.org')
34-
True
35-
>>>
26+
.. code-block:: python
3627
37-
These will try to open the page in a new browser window or tab, if possible and supported
38-
by the browser.
39-
If you want to open a page in a specific browser, you can use the webbrowser.get()
40-
function to specify a particular browser. For example:
28+
>>> # Open the page in a new browser window
29+
>>> webbrowser.open_new('http://www.python.org')
30+
True
31+
>>>
4132
42-
>>> c = webbrowser.get('firefox')
43-
>>> c.open('http://www.python.org')
44-
True
45-
>>> c.open_new_tab('http://docs.python.org')
46-
True
47-
>>>
33+
>>> # Open the page in a new browser tab
34+
>>> webbrowser.open_new_tab('http://www.python.org')
35+
True
36+
>>>
4837
49-
A full list of supported browser names can be found in the Python documentation.
38+
这样就可以打开一个新的浏览器窗口或者标签,只要浏览器支持就行。
39+
40+
如果你想指定浏览器类型,可以使用 ``webbrowser.get()`` 函数来指定某个特定浏览器。例如:
41+
42+
.. code-block:: python
43+
44+
>>> c = webbrowser.get('firefox')
45+
>>> c.open('http://www.python.org')
46+
True
47+
>>> c.open_new_tab('http://docs.python.org')
48+
True
49+
>>>
50+
51+
对于支持的浏览器名称列表可查阅`Python文档 <http://docs.python.org/3/library/webbrowser.html>`_
5052

5153
|
5254
5355
----------
5456
讨论
5557
----------
56-
Being able to easily launch a browser can be a useful operation in many scripts. For
57-
example, maybe a script performs some kind of deployment to a server and you’d like
58-
to have it quickly launch a browser so you can verify that it’s working. Or maybe a
59-
program writes data out in the form of HTML pages and you’d just like to fire up a
60-
browser to see the result. Either way, the webbrowser module is a simple solution.
58+
在脚本中打开浏览器有时候会很有用。例如,某个脚本执行某个服务器发布任务,
59+
你想快速打开一个浏览器来确保它已经正常运行了。
60+
或者是某个程序以HTML网页格式输出数据,你想打开浏览器查看结果。
61+
不管是上面哪种情况,使用 ``webbrowser`` 模块都是一个简单实用的解决方案。
6162

0 commit comments

Comments
 (0)