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 ...
随机推荐
- iOS显示一张图片 Objective-C
图片文件放在项目目录下 #import "ViewController.h" @interface ViewController () @end @implementation V ...
- 安装mask-rcnn问题汇总
1. I download file from https://github.com/waleedka/coco. Then I placed the file in Mask_RCNN-master ...
- 比较常见的几种代理ip类型
1.HTTP代理服务器 代理服务器英文全称是Proxy Server,他的功能就是代理网络用户去获得网络信息.形象点说:就是网络信息的中转站.通常情况下,网络浏览器直接去连接其他Internet站点取 ...
- Install Zabbix with Docker
1. mysql -uroot -p -h10.10.0.242 zabbix<schema.sqlEnter password: * ERROR 1709 (HY000) at line 86 ...
- 二叉查找树(Binary Search Tree)
Date:2019-06-25 14:40:32 基本操作 注意:数据量较大时,插入建树的时间复杂度会很高,慎用! //查找 void Search(node *root, int x) { if(r ...
- react antD 日期选择
<DatePicker disabledDate={disabledDate} onChange={this.onChange} /> //创建时间禁用大于当前时间 <moment( ...
- 出生年 (15 分) C解法
出生年 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相同"的要求.本题 ...
- js 的静态获取和动态获取
静态获取方法 document.getElementById obj.querySelector obj.querySelectorAll 动态获取方法(每次使用时候会回去重新获取一次) obj.ge ...
- iOS多媒体框架介绍
媒体层 媒体层包含图形技术.音频技术和视频技术,这些技术相互结合就可为移动设备带来最好的多媒体体验,更重要的是,它们让创建外观音效俱佳的应用程序变得更加容易.您可以使用iOS的高级框架更快速地创建高级 ...
- MySQL数据库开启、关闭、查看函数功能的方法
应用 MySQL 时,会遇到不能创建函数的情况.出现如下错误信息: ERROR 1418 : This function has none of DETERMINISTIC, NO SQL, or R ...