Python自动调用IE打开某个网站的方法


Posted in Python onJune 03, 2015

本文实例讲述了Python自动调用IE打开某个网站的方法。分享给大家供大家参考。具体实现方法如下:

import win32gui 
import win32com 
import win32com.client 
import pythoncom 
import time 
class Test: 
  def runtest(self): 
    print 'test' 
class EventHandler: 
  def OnVisible(self,visible): 
    global bVisibleEventFired 
    bVisibleEventFired = 1 
  def OnDownloadBegin(self): 
    print 'DownloadBegin' 
    self.runtest() 
    self.value = 1 
  def OnDownloadComplete(self): 
    print 'DownloadComplete' 
    self.value += 1 
  def OnDocumentComplete(self,pDisp=pythoncom.Missing,URL=pythoncom.Missing): 
    print 'documentComplete of %s' %URL 
    print self.value 
class H(Test,EventHandler): 
  pass 
ie = win32com.client.DispatchWithEvents('InternetExplorer.Application',H)
ie.Visible = 1 
ie.Navigate("3water.com") 
pythoncom.PumpMessages() 
ie.Quit()

运行该程序可打开3water.com网站,同时输出如下结果:

DownloadBegin
test
DownloadComplete
DownloadBegin
test
DownloadComplete
documentComplete of http://pos.baidu.com/acom?adn=0&at=128&aurl=&cad=1&ccd=32&cec=gb2312&cfv=17&ch=0&col=zh-cn&conOP=0&cpa=1&dai=1&dis=0&layout_filter=rank%2Cimage<r=<u=http%3A%2F%2F3water.com%2F&lunum=6&n=3water_cpr&pcs=1387x729&pis=10000x10000&ps=2348x191&psr=1440x900&pss=1387x2350&qn=6a0cce8cf992d19c&rad=&rsi0=1000&rsi1=60&rsi5=4&rss0=&rss1=&rss2=&rss3=&rss4=&rss5=&rss6=&rss7=&scale=&skin=tabcloud_skin_6&stid=5&td_id=1919103&tn=baiduCustSTagLinkUnit&tpr=1433304842125&ts=1&version=2.0&xuanting=0&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u1919103&ti=%E8%84%9A%E6%9C%AC%E4%B9%8B%E5%AE%B6_3water.com&tt=1433304842078.47.125.125
2
documentComplete of https://3water.com/
2
DownloadBegin
test
DownloadComplete
documentComplete of http://pos.baidu.com/wh/o.htm?ltr=&cf=u
2
DownloadBegin
test
DownloadComplete

希望本文所述对大家的Python程序设计有所帮助。

Python 相关文章推荐
Python的高级Git库 Gittle
Sep 22 Python
Python Web框架Flask中使用新浪SAE云存储实例
Feb 08 Python
详解python并发获取snmp信息及性能测试
Mar 27 Python
基于DataFrame改变列类型的方法
Jul 25 Python
django如何连接已存在数据的数据库
Aug 14 Python
Python中如何导入类示例详解
Apr 17 Python
python中time库的实例使用方法
Oct 31 Python
Python实现报警信息实时发送至邮箱功能(实例代码)
Nov 11 Python
Pytorch中Tensor与各种图像格式的相互转化详解
Dec 26 Python
Python任务调度模块APScheduler使用
Apr 15 Python
关于Python不换行输出和不换行输出end=““不显示的问题(亲测已解决)
Oct 27 Python
手把手教你配置JupyterLab 环境的实现
Feb 02 Python
Python找出文件中使用率最高的汉字实例详解
Jun 03 #Python
Python实现Windows上气泡提醒效果的方法
Jun 03 #Python
Python捕捉和模拟鼠标事件的方法
Jun 03 #Python
Python while、for、生成器、列表推导等语句的执行效率测试
Jun 03 #Python
Python fileinput模块使用实例
Jun 03 #Python
以windows service方式运行Python程序的方法
Jun 03 #Python
自己编程中遇到的Python错误和解决方法汇总整理
Jun 03 #Python
You might like
PHP基础知识回顾
2012/08/16 PHP
PHP+jquery+ajax实现即时聊天功能实例
2014/12/23 PHP
php实现mysql数据库连接操作及用户管理
2015/11/08 PHP
PHP 的Opcache加速的使用方法
2017/12/29 PHP
PHP面向对象五大原则之单一职责原则(SRP)详解
2018/04/04 PHP
setInterval 和 setTimeout会产生内存溢出
2008/02/15 Javascript
JavaScript高级程序设计 阅读笔记(十三) js定义类或对象
2012/08/14 Javascript
js形成页面的一种遮罩效果实例代码
2014/01/04 Javascript
JQuery中serialize()用法实例分析
2015/02/06 Javascript
微信中一些常用的js方法汇总
2015/03/12 Javascript
jQuery根据用户电脑是mac还是pc加载对应样式的方法
2015/06/26 Javascript
jQuery实时显示鼠标指针位置和键盘ASCII码
2016/03/28 Javascript
js实现华丽的九九乘法表效果
2017/03/29 Javascript
socket.io学习教程之深入学习篇(三)
2017/04/29 Javascript
分析javascript原型及原型链
2018/03/18 Javascript
vue 中基于html5 drag drap的拖放效果案例分析
2018/11/01 Javascript
基于Webpack4和React hooks搭建项目的方法
2019/02/05 Javascript
带你使用webpack快速构建web项目的方法
2020/11/12 Javascript
[58:09]Spirit vs NB Supermajor小组赛 A组败者组决赛 BO3 第三场 6.2
2018/06/03 DOTA
python变量不能以数字打头详解
2016/07/06 Python
使用python实现个性化词云的方法
2017/06/16 Python
Python实现随机生成手机号及正则验证手机号的方法
2018/04/25 Python
python3.x实现base64加密和解密
2019/03/28 Python
Python字符串的常见操作实例小结
2019/04/08 Python
Python利用pandas处理Excel数据的应用详解
2019/06/18 Python
Pandas 重塑(stack)和轴向旋转(pivot)的实现
2019/07/22 Python
python时间序列数据转为timestamp格式的方法
2020/08/03 Python
Python基础进阶之海量表情包多线程爬虫功能的实现
2020/12/17 Python
Scotch Porter官方网站:男士美容产品
2020/08/31 全球购物
简历的个人自我评价范文
2014/01/03 职场文书
弘扬职业精神演讲稿
2014/03/20 职场文书
中学生旷课检讨书模板
2014/10/08 职场文书
培训师岗位职责
2015/02/14 职场文书
反腐倡廉学习心得体会范文
2015/08/15 职场文书
Win10系统下配置Java环境变量
2021/06/13 Java/Android
浅谈Redis 中的过期删除策略和内存淘汰机制
2022/04/03 Redis