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实现k均值算法示例(k均值聚类算法)
Mar 16 Python
python网络编程学习笔记(四):域名系统
Jun 09 Python
django使用图片延时加载引起后台404错误
Apr 18 Python
python3解析库BeautifulSoup4的安装配置与基本用法
Jun 26 Python
解决安装python库时windows error5 报错的问题
Oct 21 Python
神经网络相关之基础概念的讲解
Dec 29 Python
python如何爬取网站数据并进行数据可视化
Jul 08 Python
python实现邮件自动发送
Aug 10 Python
python输出数组中指定元素的所有索引示例
Dec 06 Python
使用Pytorch训练two-head网络的操作
May 28 Python
pandas中DataFrame数据合并连接(merge、join、concat)
May 30 Python
python获取字符串中的email
Mar 31 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中的curl使用入门教程和常见用法实例
2014/04/10 PHP
laravel-admin的图片删除实例
2019/09/30 PHP
JavaScript 函数式编程的原理
2009/10/16 Javascript
javascript中兼容主流浏览器的动态生成iframe方法
2014/05/05 Javascript
JavaScript设置、获取、清除单值和多值cookie的方法
2015/11/17 Javascript
JS 对象(Object)和字符串(String)互转方法
2016/05/20 Javascript
浅谈javascript中关于日期和时间的基础知识
2016/07/13 Javascript
js当前页面登录注册框,固定div,底层阴影的实例代码
2016/10/04 Javascript
Bootstrap免费字体和图标网站(值得收藏)
2017/03/16 Javascript
js canvas实现简单的图像扩散效果
2020/06/28 Javascript
利用JS如何计算字符串所占字节数示例代码
2017/09/13 Javascript
微信小程序canvas实现刮刮乐效果
2018/07/09 Javascript
vue.draggable实现表格拖拽排序效果
2018/12/01 Javascript
layui中的switch开关实现方法
2019/09/03 Javascript
js实现图片上传即时显示效果
2019/09/30 Javascript
javascript 关于赋值、浅拷贝、深拷贝的个人理解
2019/11/01 Javascript
解决vue动态下拉菜单 有数据未反应的问题
2020/08/06 Javascript
python中的全局变量用法分析
2015/06/09 Python
Python 关于反射和类的特殊成员方法
2017/09/14 Python
numpy基础教程之np.linalg
2019/02/12 Python
python2.7 安装pip的方法步骤(管用)
2019/05/05 Python
详解Python 多线程 Timer定时器/延迟执行、Event事件
2019/06/27 Python
Numpy 中的矩阵求逆实例
2019/08/26 Python
python 怎样将dataframe中的字符串日期转化为日期的方法
2019/09/26 Python
django rest framework serializer返回时间自动格式化方法
2020/03/31 Python
德国街头和运动文化高品质商店:BSTN Store
2017/08/26 全球购物
美国和加拿大房车出售在线分类广告:RVT.com
2018/04/23 全球购物
法务专员岗位职责
2014/01/02 职场文书
经理助理岗位职责
2014/03/05 职场文书
五四青年节演讲稿
2014/05/26 职场文书
2014年纪检监察工作总结
2014/11/11 职场文书
给老婆的检讨书
2015/01/27 职场文书
2015年初中生自我评价范文
2015/03/03 职场文书
有关骆驼祥子的读书笔记
2015/06/26 职场文书
小学语文教学反思范文
2016/03/03 职场文书
centos8安装nginx1.9.1的详细过程
2021/08/02 Servers