Python基础--webbrowser
非常多人,一提到Python,想到的就是爬虫。我会一步一步的教你怎样爬出某个站点。
今天就先介绍一下webbrowser,这个词您肯定不会陌生。对,就是浏览器。
看看Python中对webbrowser的描写叙述:
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的简单有用了:
首先当然是导入webbrowser模块了:
import webbrowser
可是这个时候等等。我有话要说。
在C++中,假设一个变量的名称太长,我们往往有用typedef进行缩写。Python中。相同能够,比方我们嫌webbrowser太长了。希望用web替代,则能够这么导入:
import webbrowser as web
接下来就介绍一些函数了:
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).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.
Changed in version 2.5: new can now be 2.
webbrowser.
open_new
(url)-
Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.
webbrowser.
open_new_tab
(url)-
Open url in a new page (“tab”) of the default browser, if possible, otherwise equivalent to
open_new()
.New in version 2.5.
webbrowser.
get
([name])-
Return a controller object for the browser type name. If name is empty, return a controller for a default browser appropriate to the caller’s environment.
webbrowser.
register
(name, constructor[, instance])-
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 isNone
, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may beNone
. -
上面的都是官方的英文描写叙述,单词都非常easy。假设看不懂,劝你还是别编程了。
-
以下是几个应用实例:
-
1用指定的浏览器来载入url
import webbrowser b = webbrowser.get('chrome')
b.open('http://blog.csdn.net/wangshubo1989')
2对照应用
import webbrowser url = 'http://blog.csdn.net/wangshubo1989'# 默认浏览器打开webbrowser.open_new(url) # opens in default browser# 使用 safari 打开webbrowser.get('safari').open_new(url)# 在浏览器中用新标签打开webbrowser.open_new_tab(url) # opens in default browser# 在Safari中新建标签并打开urlwebbrowser.get('safari').open_new_tab(url)
关闭浏览器
对了,忘了写怎样关闭浏览器了
运行命令行就可以:
import os
os.system('taskkill /F /IM chrome.exe')
Python基础--webbrowser的更多相关文章
- python基础系列教程——Python3.x标准模块库目录
python基础系列教程——Python3.x标准模块库目录 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata ...
- python基础31[常用模块介绍]
python基础31[常用模块介绍] python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的. 常用的li ...
- python基础全部知识点整理,超级全(20万字+)
目录 Python编程语言简介 https://www.cnblogs.com/hany-postq473111315/p/12256134.html Python环境搭建及中文编码 https:// ...
- python之最强王者(2)——python基础语法
背景介绍:由于本人一直做java开发,也是从txt开始写hello,world,使用javac命令编译,一直到使用myeclipse,其中的道理和辛酸都懂(请容许我擦干眼角的泪水),所以对于pytho ...
- Python开发【第二篇】:Python基础知识
Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...
- Python小白的发展之路之Python基础(一)
Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...
- Python之路3【第一篇】Python基础
本节内容 Python简介 Python安装 第一个Python程序 编程语言的分类 Python简介 1.Python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum) ...
- 进击的Python【第三章】:Python基础(三)
Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...
- 进击的Python【第二章】:Python基础(二)
Python基础(二) 本章内容 数据类型 数据运算 列表与元组的基本操作 字典的基本操作 字符编码与转码 模块初探 练习:购物车程序 一.数据类型 Python有五个标准的数据类型: Numbers ...
随机推荐
- select count(1) 和 select count(*)的区别
统计一个表T有多少行数据,通常写法是: 查询A:select count(*) from T 但也可以采用下面语句来查: 查询B:select count(1) from T 结果通常是一样的.那么二 ...
- servU服务器连接不上问题的解决
在服务器上安装了servU64位版,建立了用户,设置了防火墙,正常启动. 但在客户端发出FTP://服务器IP 命令后,弹出输入用户名和密码的对话框,输入正确的用户名和密码后,却始终连接不上. ftp ...
- Anaconda安装xgboost的过程和踩过的坑
win10下安装xgb,安装的过程波折起伏,花了5个小时,给后来人做参考喽 第一次尝试 利用以下两个软件 Git for Windows.MINGW进行安装. 安装可以参考:(https://blog ...
- <MyBatis>入门五 查询的返回值处理
select : 返回对象: <select id = " " resultType= "对象的全类名" /> List: <sele ...
- MySql报Packet for query is too large错误
mysql中执行sql的时候报以下错误:Packet for query is too large (1354 > 1024) 原因是mysql一次接收的报文太长,需要调整服务器参数max_al ...
- Hadoop Mapreduce 中的Partitioner
Partitioner的作用的对Mapper产生的中间结果进行分片,以便将同一分组的数据交给同一个Reduce处理,Partitioner直接影响Reduce阶段的负载均衡. MapReduce提供了 ...
- Linux学习笔记记录(五)
- 简述systemd的新特性及unit常见类型分析、使用systemd管理编译安装的nginx
1. systemd新特性 并行处理(同时启动)所有服务. 基于依赖关系定义的服务控制逻辑 系统状态快照 按需激活进程,只有第一次被访问时才会真正启动: 2. systemd的常见unit类型 Ser ...
- ubuntu root用户登陆
sudo vi /etc/lightdm/lightdm.conf (如果没有该文件则创建,内容如下) [SeatDefaults] user-session=ubuntu greeter-ses ...
- java 十三周总结