Python之浏览器打开有趣的例子
2018-03-06 14:25
344 查看
note:版本v1
项目描述:
用python实现自动提醒休息
此处我用浏览器中的三个MV视频作为提醒
环境:
python3.5
win10
webbrowser模块
time模块
sys模块
代码如下:
total_breaks = 3
break_count = 0
note:版本v2
更新:
1.用指定浏览器打开网页
2.定时打开并且定时关闭
提示:
1.windows命令:taskkill /F /IM iexplore.exe(
关闭程序方法—os.system(‘taskkill /F /IM iexplore.exe’))
2.linux 命令是:killall(kill不建议使用) /F /IM qq.exe
( #linux中:os.system(‘killall /F /IM qq.exe’)
import sys
import webbrowser
import time
import os
sys.path.append(“libs”)
total_breaks = 3
break_count = 0
off = 0
print(‘This programe started on’ + time.ctime())
while (break_count < total_breaks):
time.sleep(30*60) #半小时提醒一次
url1 = ‘http://v.yinyuetai.com/video/3161181’
url2 =’http://v.yinyuetai.com/video/3158917?vid=3161181’
url3 = ‘http://v.yinyuetai.com/video/3157203?vid=3161181’
IEPath = r’C:/Program Files/Internet Explorer/iexplore.exe’ # 例如我的:C:/Program Files/Internet Explorer/iexplore.exe
webbrowser.register(‘IE’, None,
webbrowser.BackgroundBrowser(IEPath)) # 这里的’IE’可以用其它任意名字,如IE11,这里将想打开的浏览器保存到’IE’
项目描述:
用python实现自动提醒休息
此处我用浏览器中的三个MV视频作为提醒
环境:
python3.5
win10
webbrowser模块
time模块
sys模块
代码如下:
#!/usr/bin/env python #-*- coding:UTF-8 -*- import sys import webbrowser import time sys.path.append("libs")
total_breaks = 3
break_count = 0
print('This programe started on' + time.ctime()) while (break_count < total_breaks): time.sleep(2*60*60) #两个小时提醒一次 url1 = 'http://v.yinyuetai.com/video/3161181' url2 ='http://v.yinyuetai.com/video/3158917?vid=3161181' url3 = 'http://v.yinyuetai.com/video/3157203?vid=3161181' if break_count < 1: webbrowser.open(url1) elif break_count < 2: webbrowser.open(url2) else: webbrowser.open(url3) print (webbrowser.get()) break_count +=1
note:版本v2
更新:
1.用指定浏览器打开网页
2.定时打开并且定时关闭
提示:
1.windows命令:taskkill /F /IM iexplore.exe(
关闭程序方法—os.system(‘taskkill /F /IM iexplore.exe’))
2.linux 命令是:killall(kill不建议使用) /F /IM qq.exe
( #linux中:os.system(‘killall /F /IM qq.exe’)
import sys
import webbrowser
import time
import os
sys.path.append(“libs”)
total_breaks = 3
break_count = 0
off = 0
print(‘This programe started on’ + time.ctime())
while (break_count < total_breaks):
time.sleep(30*60) #半小时提醒一次
url1 = ‘http://v.yinyuetai.com/video/3161181’
url2 =’http://v.yinyuetai.com/video/3158917?vid=3161181’
url3 = ‘http://v.yinyuetai.com/video/3157203?vid=3161181’
IEPath = r’C:/Program Files/Internet Explorer/iexplore.exe’ # 例如我的:C:/Program Files/Internet Explorer/iexplore.exe
webbrowser.register(‘IE’, None,
webbrowser.BackgroundBrowser(IEPath)) # 这里的’IE’可以用其它任意名字,如IE11,这里将想打开的浏览器保存到’IE’
if break_count < 1: webbrowser.get('IE').open(url1, new=1, autoraise=True) time.sleep(2*60) #播放两分钟停止 os.system('taskkill /F /IM iexplore.exe') off +=1 elif break_count < 2 and off > 0: webbrowser.get('IE').open(url2, new=1, autoraise=True) time.sleep(2 * 60) os.system('taskkill /F /IM iexplore.exe') off +=1 elif off > 1: webbrowser.get('IE').open(url3, new=1, autoraise=True) time.sleep(2 * 60) os.system('taskkill /F /IM iexplore.exe') off += 1 print (webbrowser.get()) break_count +=1
相关文章推荐
- 使用python调用浏览器并打开一个网址的例子
- 使用python调用浏览器并打开一个网址的例子
- Python读取并执行本地文件中的链接,打开搜狐浏览器,循环执行
- python打开浏览器指定网页并填写内容---微信篇
- python调用浏览器,打开一个网址
- python+selenium自动化不打开浏览器测试
- 使用Python2.7操作Selenium2时只打开浏览器不load URL的解决方法
- python 的 IDLE 无法连接以及 jupyter notebook 无法打开浏览器
- python模拟浏览器打开百度首页并登录或者点击首页新闻并保存网页
- pythonGUI编程打开默认浏览器
- python——利用python通过浏览器打开博客页面
- python指定浏览器打开特定URL
- 【Python + selenium】在浏览器打开新页签,打开方式
- python+selelnium打开和关闭浏览器
- python用图片浏览器打开图片
- Python Webdriver 重新使用已经打开的浏览器实例
- [Python][小知识][NO.3] Python 使用系统默认浏览器打开指定URL的网址
- Python Webdriver 重新使用已经打开的浏览器实例
- python | 打开浏览器webbrowser
- python_随机调用一个浏览器打开网页