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使用in操作符时元组和数组的区别分析
May 19 Python
Python 实现 贪吃蛇大作战 代码分享
Sep 07 Python
Python编程实现输入某年某月某日计算出这一天是该年第几天的方法
Apr 18 Python
python 爬虫 批量获取代理ip的实例代码
May 22 Python
python实现年会抽奖程序
Jan 22 Python
对Django 转发和重定向的实例详解
Aug 06 Python
Python3 chardet模块查看编码格式的例子
Aug 14 Python
python 协程 gevent原理与用法分析
Nov 22 Python
opencv之为图像添加边界的方法示例
Dec 26 Python
dpn网络的pytorch实现方式
Jan 14 Python
pytorch实现Tensor变量之间的转换
Feb 17 Python
在Windows上安装和配置 Jupyter Lab 作为桌面级应用程序教程
Apr 22 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
全国FM电台频率大全 - 27 陕西省
2020/03/11 无线电
东方红 - 来复式再生机的修复
2021/03/02 无线电
浅析PHP编程中10个最常见的错误
2014/08/08 PHP
php截取字符串函数分享
2015/02/02 PHP
PHP getallheaders无法获取自定义头(headers)的问题
2016/03/23 PHP
Thinkphp3.2.3分页使用实例解析
2016/07/28 PHP
将input file的选择的文件清空的两种解决方案
2013/10/21 Javascript
js事件绑定快捷键以ctrl+k为例
2014/09/30 Javascript
node.js使用npm 安装插件时提示install Error: ENOENT报错的解决方法
2014/11/20 Javascript
JavaScript实现的圆形浮动标签云效果实例
2015/08/06 Javascript
深入理解JQuery中的事件与动画
2016/05/18 Javascript
浅析jQuery操作select控件的取值和设值
2016/12/07 Javascript
在vue项目中,使用axios跨域处理
2018/03/07 Javascript
浅谈Vue路由快照实现思路及其问题
2018/06/07 Javascript
JavaScript类数组对象转换为数组对象的方法实例分析
2018/07/24 Javascript
解决LayUI数据表格复选框不居中显示的问题
2019/09/25 Javascript
Python里隐藏的“禅”
2014/06/16 Python
用Python实现服务器中只重载被修改的进程的方法
2015/04/30 Python
python用reduce和map把字符串转为数字的方法
2016/12/19 Python
Python变量和字符串详解
2017/04/29 Python
python文本数据相似度的度量
2018/03/12 Python
python用插值法绘制平滑曲线
2021/02/19 Python
Python Pandas中根据列的值选取多行数据
2019/07/08 Python
Django框架model模型对象验证实现方法分析
2019/10/02 Python
python实现将列表中各个值快速赋值给多个变量
2020/04/02 Python
将keras的h5模型转换为tensorflow的pb模型操作
2020/05/25 Python
Python实现哲学家就餐问题实例代码
2020/11/09 Python
python实现马丁策略的实例详解
2021/01/15 Python
印度尼西亚最完整和最大的在线药房网站:Farmaku.com
2019/11/23 全球购物
护理职业应聘自荐书
2013/09/29 职场文书
大学生职业生涯规划书范文
2014/01/04 职场文书
实习单位接收函模板
2014/01/10 职场文书
英文推荐信格式范文
2014/05/09 职场文书
“四风”问题整改措施和努力方向
2014/09/20 职场文书
后勤个人工作总结
2015/02/28 职场文书
永远是春天观后感
2015/06/12 职场文书