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 ...
随机推荐
- opencv3+python+pycharm报错问题(cmd命令正常)
2018-03-0223:58:59 首先在你已成功安装python的情况下运行cmd命令,下载安装opencv插件 如果在命令行可以使用 import cv2 但是在IDE上面只输入import c ...
- Git——github基本操作
基本概念 上一篇文章写到git共享仓库,但是有个局限性,就是这个仓库存在于本地,其他人无法从我们这个仓库拿到共享的内容 但是我们可以将这个共享仓库放入一个远程的服务器上,然后设置一些登录权限就能完美的 ...
- Angular——配置模块与运行模块
配置模块 通过config方法实现对模块的配置,AngularJS中的服务大部分都对应一个“provider”,用来执行与对应服务相同的功能或对其进行配置.比如$log.$http.$location ...
- 北大ACM(POJ1019-Number Sequence)
Question:http://poj.org/problem?id=1019 问题点:打表. Memory: 392K Time: 16MS Language: C++ Result: Accept ...
- Springboot + SLF4j + Log4j2 打印异常日志时,耗时要5-6秒
1.使用jps -l 查看springboot项目的进程ID 2.使用命令jstack -l 进程ID > log.txt 打印堆栈信息到文件,内容如下: "http-nio-8065 ...
- 怎么忽略ESLint校验
方法一: 打开eslint的配置文件.eslintrc.js rules: { // allow async-await 'generator-star-spacing': 'off', // all ...
- 梦想iOS版CAD控件2018.11.07更新
下载地址: http://www.mxdraw.com/ndetail_10110.html 1. 增加iOS上的CAD绘图接口和使用例子 2. 增加动态交互使用例子 3. 把Android上改 ...
- python logger日志
直接上代码 import logging import logging.handlers import datetime import time import threading from conf. ...
- 如何做到在webpack打包vue项目后,在外部动态修改配置文件
在我们做完vue项目后,只需要执行 npm run dist 就可以轻松进行打包转测试,可是如果我们临时需要修改一些配置文件比如域名,这时候我们就有点懵逼了,那就修改了再重新打一次包? NO NO N ...
- NOIP2000方格取数(洛谷,动态规划递推)
先上题目: P1004 方格取数 下面上ac代码: ///如果先走第一个再走第二个不可控因素太多 #include<bits/stdc++.h> #define ll long long ...